Special Variables
| Sr. No. | Variable & Description |
|---|---|
| 1. | $0 ôThe filename of the current script. |
| 2. | $n ôThese variables correspond to the arguments with which a script was invoked. Herenis a positive decimal number corresponding to the position of an argument (the first argument is $1, the second argument is $2, and so on). |
| 3. | $# ôThe number of arguments supplied to a script. |
| 4. | $* ôAll the arguments are double quoted. If a script receives two arguments, $* is equivalent to $1 $2. It takes input as string. For difference, run the script/unix-variable-and-difference/ |
| 5. | $@ ôAll the arguments are individually double quoted. If a script receives two arguments, $@ is equivalent to $1 $2. It takes input as array. |
| 6. | $? ôThe exit status of the last command executed. Output ÿ0Ö if all successful ÿ1Ö if unsuccessful. |
| 7. | $$ ôThe process number of the current shell. For shell scripts, this is the process ID under which they are executing. |
| 8. | $! ôThe process number of the last background command. |
| 9. | $1-$9 ôCommand Line Arguments |
Example
File Name: specialchar.sh
#!/bin/sh
echo £File Name: $0¥
echo £First Parameter : $1¥
echo £Second Parameter : $2¥
echo £Quoted Values: $@¥
echo £Quoted Values: $*¥
echo £Total Number of Parameters : $#¥
Command to Run: ./specialchar.sh Nishant Munjal