For the past few weeks, I have been working on Unix Shell, to accomplish variety of tasks such as parsing files, transferring data, updating databases etc. Today is the day, i primarily worked on Arguments. Arguments are inputs to the program, and are also referred as parameters interchangeably.
Lets see how to use the arguments in the korn shell script, beginning with unix shell annotation for arguments.
$1, $2, $3 … $n First, Second, Third… and nth Argument
$# (hash) Count of Arguments
$* (Asterisk) Arguments concatenated by space
$@ (at the rate) Array of Arguments
Here is an sample shell script “accessArguments.ksh”.
$ cat accessArguments.ksh # accessArguments.ksh echo Zeroth Argument: $0 echo First Argument: $1 echo Second Argument: $2 echo Total No. Of Arguments: $# echo Arguments: $* for var in $@ do echo Argument $var done
Now lets see the output of the above script, with inputs as 10 and 15
$ accessArguments.ksh 10 15 Zeroth Argument : accessArguments.ksh First Argument: 10 Second Argument: 15 Total No. Of Arguments: 2 Arguments: 10 15 Argument 10 Argument 15 $
Hope this example envisions you with the knowledge of using Arguments in Unix Shell.
No related posts.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=94c4adea-3b9f-44a9-b434-5d46c3a38302)



