I just wanted to chime in here since no one mentioned info or pinfo. You can find all of this info and much, much more, without even leaving the shell, by typing:
info -f "bash" -n "Shell Parameter Expansion"
Or use pinfo to add a little color.
pinfo -f "bash" -n "Shell Parameter Expansion"
A good read: pinfo bash (navigate to Basic Shell Features)
To produce this cheat sheet:
info -f "bash" -n "Shell Parameter Expansion" -o "Parameter Expansion Cheat Sheet"
In each of the cases below, WORD is subject to tilde expansion,
parameter expansion, command substitution, and arithmetic expansion.
When not performing substring expansion, using the form described
below (e.g., ‘:-’), Bash tests for a parameter that is unset or null.
Omitting the colon results in a test only for a parameter that is unset.
Put another way, if the colon is included, the operator tests for both
PARAMETER's existence and that its value is not null; if the colon is
omitted, the operator tests only for existence.
‘${PARAMETER:−WORD}’
If PARAMETER is unset or null, the expansion of WORD is
substituted. Otherwise, the value of PARAMETER is substituted.
$ v=123
$ echo ${v-unset}
123
‘${PARAMETER:=WORD}’
If PARAMETER is unset or null, the expansion of WORD is assigned to
PARAMETER. The value of PARAMETER is then substituted. Positional
parameters and special parameters may not be assigned to in this
way.
$ var=
$ : ${var:=DEFAULT}
$ echo $var
DEFAULT
‘${PARAMETER:=WORD}’
If PARAMETER is unset or null, the expansion of WORD is assigned to
PARAMETER. The value of PARAMETER is then substituted. Positional
parameters and special parameters may not be assigned to in this
way.
$ var=
$ : ${var:=DEFAULT}
$ echo $var
DEFAULT
‘${PARAMETER:?WORD}’
If PARAMETER is null or unset, the expansion of WORD (or a message
to that effect if WORD is not present) is written to the standard
error and the shell, if it is not interactive, exits. Otherwise,
the value of PARAMETER is substituted.
$ var=
$ : ${var:?var is unset or null}
bash: var: var is unset or null
‘${PARAMETER:+WORD}’
If PARAMETER is null or unset, nothing is substituted, otherwise
the expansion of WORD is substituted.
$ var=123
$ echo ${var:+var is set and not null}
var is set and not null
Substring expansion and more is covered. Just a sample. Not going to copy it all here. It's a whole chapter!
The following examples illustrate substring expansion using
positional parameters:
$ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
$ echo ${@:7}
7 8 9 0 a b c d e f g h
$ echo ${@:7:0}
$ echo ${@:7:2}
7 8
$ echo ${@:7:-2}
bash: -2: substring expression < 0
$ echo ${@: -7:2}
b c
$ echo ${@:0}
./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
$ echo ${@:0:2}
./bash 1
$ echo ${@: -7:0}