Bash Special Parameters
Special parameters are variables that Bash sets for you. You can read them, but not assign to them.
The most used are $# (number of arguments), $@ (all arguments) and $? (exit status of the last command).
Inspect the arguments
Save this as info.sh:
#!/bin/bash
echo "Script: $0"
echo "Count: $#"
echo "All: $@"
Run it:
./info.sh red green blue
Script: ./info.sh
Count: 3
All: red green blue
The Special Parameters
| Parameter | Holds |
|---|---|
$# | The number of arguments |
$@ | All arguments, each one a separate word when quoted as "$@" |
$* | All arguments, joined into one word when quoted as "$*" |
$? | The exit status of the last command |
$0 | The name of the script |
$$ | The process ID of the current shell |
$! | The process ID of the last background job |