13.2.3 Shell parameters
Several special parameters to remember:
$0 = name of the shell or shell script
$1 = first(1) shell argument
...
$9 = ninth(9) shell argument
$# = number of positional parameters
"$*" = "$1 $2 $3 $4 ... $n"
"$@" = "$1" "$2" "$3" "$4" ... "$n"
$? = exit status of the most recent command
$$ = PID of this shell script
$! = PID of most recently started background job
Basic parameter expansions to remember:
Form If var is set If var is not set
${var:-string} $var string
${var:+string} string null
${var:=string} $var string
(and run var=string)
${var:?string} $var (echo string and then exit)
Here, the colon `:' in all of these operators is actually optional.
Basic parameter substitutions to remember:
Form Result
${var%suffix} Remove smallest suffix pattern
${var%%suffix} Remove largest suffix pattern
${var#prefix} Remove smallest prefix pattern
${var##prefix} Remove largest prefix pattern