In positional Parameter are variables that contain the contents of the command line. These variables are $0 to $9. The script itself is stored in $0, first parameter is $1 and so on. This is how parameters are passed to the script.
$ sh <scirpt_name>.sh parameter1 parameter2 ....
Ex:
echo "the script: $0 is passed with first parameter value: $1 and second parameter: $2"
dlyelgg@lgpbd1100[(IPC2-Gold-EDGE) ~/srik]$ sh Positional_Parameters.sh 1 2
$ sh <scirpt_name>.sh parameter1 parameter2 ....
Ex:
echo "the script: $0 is passed with first parameter value: $1 and second parameter: $2"
dlyelgg@lgpbd1100[(IPC2-Gold-EDGE) ~/srik]$ sh Positional_Parameters.sh 1 2
O/P:
the script: Positional_Parameters.sh is passed with first parameter value: 1 and second parameter: 2
-----------------------
To access all parameters in positional parameters use $@
Ex:
for para in $@
do
echo "The parameters passed to the script: $0 are $para"
done
-----------------------
To access all parameters in positional parameters use $@
Ex:
for para in $@
do
echo "The parameters passed to the script: $0 are $para"
done
dlyelgg@lgpbd1100[(IPC2-Gold-EDGE) ~/srik]$ sh Accessing_PossitionalParameters.sh 1 2 3
'ccessing_PossitionalParameters.sh: line 2: syntax error near unexpected token `do
'ccessing_PossitionalParameters.sh: line 2: `do
No comments:
Post a Comment