Command-line parameters are called $0, $1, $2, …
e.g.:
$ shell-script param1 param2 param3 param4
Special Built-in Variables:
$@: lists all the parameters
$*: lists all the parameters
$?: exit status of last command
$$: processid of the current shell
e.g.:
1. Create a script called parametersample.
#! /bin/sh
echo $0 is the full name of this shell script
echo "first parameter is $1"
echo "second parameter is $2"
echo "third parameter is $3"
echo "total number of parameters is $#"
echo "process ID is $$"
2. Make the file executable
chmod +x parametersample
3. Execute the file.
sh parametersample 1 2 3 4
or
./parametersample 1 2 3 4
4. Check the output.
parametersample is the full name of this shell script
first parameter is 1
parameter is 2
parameter is 3
total number of parameters is 4
process ID is 1693