Categories
Shell script

Command line arguements

eg:

$ myshell foo bar

 Shell Script name i.e. myshell
 First command line argument passed to myshell i.e. foo
 Second command line argument passed to myshell i.e. bar

In shell if we wish to refer this command line argument we refer above as follows

 myshell it is $0
 foo it is $1
 bar it is $2

Here $# (built in shell variable ) will be 2 (Since foo and bar only two Arguments), Please note at a time such 9 arguments can be used from $1..$9, You can also refer all of them by using $* (which expand to `$1,$2…$9`). Note that $1..$9 i.e command line arguments to shell script is know as “positional parameters“.


Leave a Reply

Your email address will not be published. Required fields are marked *