passing an argument to a script

by rajesh 2008-08-08 12:19:12

consider that you have written a script named test.sh

while executing the script you can pass argument to the script as
>sh test.sh argumnet1
example: >sh test.sh rajesh


to get the argument inside the script you have to just use $1
yes $1 will fetch first argument.

similarly you can pass as many arguments and fetch them using $1, $2 so on...

example: >sh test.sh rajesh kumar
test.sh
echo "first argument $1"
echo "second argument $2"


the output will be
first argument rajesh
second argument kumar

Tagged in:

2547
like
0
dislike
0
mail
flag

You must LOGIN to add comments