background img
banner
Sep 26, 2011
277 Views
0 0

Command line arguements

Written by
banner

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“.


Article Categories:
Shell script
banner

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.