Parameters Set by the Shell
From Linux Shell Scripting Tutorial - A Beginner's handbook
Bash shell set several special parameters. For example $? (see return values section) holds the return value of the executed command.
- All command line parameters or arguments can be accessed via $1, $2, $3,..., $9.
- $* holds all command line parameters or arguments.
- $# holds the number of positional parameters.
- $- holds flags supplied to the shell.
- $? holds the return value set by the previously executed command.
- $$ holds the process number of the shell (current shell).
- $! hold the process number of the last background command.
- $@ holds all command line parameters or arguments.
Use echo command to display special shell parameters:
echo $#
You can store them to a shell variables as follows:
status=$? [ $status -eq 0 ] && echo "Lighttpd ... [Ok]" || echo "Lighttpd ... [Failed]"
- Assignment to special parameter is not allowed:
# okay status=$? # noop not allowed $?=-1