Operating System - HP-UX
1827975 Members
2446 Online
109973 Solutions
New Discussion

Query on Command line argument

 
P Arumugavel
Respected Contributor

Query on Command line argument

Hi Experts,

 

I am newbie to scripting. While I come through some docs, I crossed one topic called 'Arguments to Shell Programs". I am not able to understand that at all. If you could make me understand in a way, it would be highly appreciated.

 $0 - The command name

$1 - The first argument

$2 - The second argument

.

.

$9 - The ninth argument

$# - The number of command line arguments

$*

$n

 

Please explain about above also.

Thanks in advance

 

Rgds...

 

3 REPLIES 3

Re: Query on Command line argument

I guess google is broken again then?

 

There are so many shell script tutorials out there on the internet, any reply here is really just repetition

 

http://www.freeos.com/guides/lsst/ch02sec13.html

 

Seems like a pretty simple intro to command line arguments


I am an HPE Employee
Accept or Kudo
Dennis Handly
Acclaimed Contributor

Re: Query on Command line argument

Why not try it out for yourself?

$ your-script.sh p1 p2 p3 p4 p5 p6 p7

 

In your-script.sh:

echo "$0: args: $@"

echo "$0 has $# args"

echo "$1"

echo "$2"

James R. Ferguson
Acclaimed Contributor

Re: Query on Command line argument

Hi:

 

The easiest way to learn is to read and *write*.  Your scripts can be as simple as Dennis suggested.  The important part is to practice.  Where possible, run code that you see to discover how and why it works.  An excellent source of good scripts and tutorials (including one germane to your question here) is:

 

http://www.shelldorado.com/

 

...http://www.shelldorado.com/goodcoding/cmdargs.htmland, specifically to this question:

 

Regards!

 

...JRF...