LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2018, 02:38 AM   #1
nisha.bhatt007@gmail.com
LQ Newbie
 
Registered: May 2018
Posts: 1

Rep: Reputation: Disabled
HI, I have made a script abc.sh, now i want it to display its version when i run it. suppose im running script, ./abc.sh -v, i want it to d


HI,

I have made a script abc.sh, now i want it to display its version when i run it.
suppose im running script, ./abc.sh -v, i want it to display its version number.
 
Old 05-22-2018, 02:52 AM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by nisha.bhatt007@gmail.com View Post
HI,

I have made a script abc.sh, now i want it to display its version when i run it.
suppose im running script, ./abc.sh -v, i want it to display its version number.
OK, you say you have made "a script", but you don't show us what it is. You need to post it, along with your efforts to resolve your issue(s).

I don't mean to be rude, but we don't do people's homework for them. We are happy to help you where you get stuck, but we expect that you have made at least some effort of you're own.

Can you post your efforts and use CODE tags when posting scripts - so it's easy to read it.

I've asked for this to moved to the Programming forum.
 
Old 05-22-2018, 04:20 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,473

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Look at
Code:
getopts
for handling options, or if you want something highly simplistic just look at Positional Parameter handling.
 
Old 05-22-2018, 04:56 AM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
A shell script is only plain readable English text. If the script does not store or refer to a version number store somewhere else, there is clearly no way it can display the version number. Also the version number is not stored in the file header.

OK
 
Old 05-22-2018, 05:45 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
Yes, either getopts() or positional parameters will do the job of collecting run time options which you can use. I'm throwing in some links there since they are hard to find in all the noise in the search engines these days.
 
Old 05-22-2018, 07:16 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,879
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by nisha.bhatt007@gmail.com View Post
HI,

I have made a script abc.sh, now i want it to display its version when i run it.
suppose im running script, ./abc.sh -v, i want it to display its version number.
Hi nisha.bhatt007,

Please post a copy of your script as well as what you intend to say when the version request argument is used.

Please also take a look at the advice offered by other members about parsing script options.

Do you understand how to output information when you have parsed an option and then need to inform the user about the script version?

In the future, it will be helpful to provide more details of your question.
 
1 members found this post helpful.
Old 05-22-2018, 09:35 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
agree, define "it" so one can show you how to assign/obtain the version to it so it can show its version to the user. get it?

it is implying the scripts version, did you by any chance use an echo command in your script, and use a variable assignment? maybe put the two ideas together and see what you come up with.

Last edited by BW-userx; 05-22-2018 at 09:38 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect a m.domain.com/abc to a ip address 123.123.123.123/abc? elok Linux - Server 5 05-27-2010 09:05 PM
Setup Apache so Webmin can be accessed like abc.com/webmin instead of abc.com:10000 rtoney5 Linux - Software 6 04-08-2010 12:33 PM
Compare string (capitol letters) abc to ABC Willy Fog Linux - Newbie 4 09-17-2009 11:36 AM
How to set linux environment variable like abc.abc (With DOT in the string) super_hill Linux - General 1 12-03-2008 07:37 PM
Need to update some file abc in my script xyz.sh sumitdevbharadwaj Programming 6 11-09-2008 01:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration