vim: ft=help:tw=78:ts=8:norl:nolist:nonu:noml:

+--------------------+----------------------+-----------------+-----------------+
|   Expression       |       parameter      |     parameter   |    parameter    |
|   in script:       |   Set and Not Null   |   Set But Null  |      Unset      |
+--------------------+----------------------+-----------------+-----------------+
| ${parameter:-word} | substitute parameter | substitute word | substitute word |
| ${parameter-word}  | substitute parameter | substitute null | substitute word |
| ${parameter:=word} | substitute parameter | assign word     | assign word     |
| ${parameter=word}  | substitute parameter | substitute null | assign word     |
| ${parameter:?word} | substitute parameter | error, exit     | error, exit     |
| ${parameter?word}  | substitute parameter | substitute null | error, exit     |
| ${parameter:+word} | substitute word      | substitute null | substitute null |
| ${parameter+word}  | substitute word      | substitute word | substitute null |
+--------------------+----------------------+-----------------+-----------------+

+--------------------+----------------------+-----------------+-----------------+
|   Expression       |  When FOO="world"    |  When FOO=""    |    unset FOO    |
|   in script:       |  (Set and Not Null)  |  (Set But Null) |     (Unset)     |
+--------------------+----------------------+-----------------+-----------------+
| ${FOO:-hello}      | world                | hello           | hello           |
| ${FOO-hello}       | world                | ""              | hello           |
| ${FOO:=hello}      | world                | FOO=hello       | FOO=hello       |
| ${FOO=hello}       | world                | ""              | FOO=hello       |
| ${FOO:?hello}      | world                | error, exit     | error, exit     |
| ${FOO?hello}       | world                | ""              | error, exit     |
| ${FOO:+hello}      | hello                | ""              | ""              |
| ${FOO+hello}       | hello                | hello           | ""              |
+--------------------+----------------------+-----------------+-----------------+

+----------------------+--------------+-----------------------+-----------------------+
| parameter expansion  | VARIABLE set | VARIABLE empty        | VARIABLE unset        |
+----------------------+--------------+-----------------------+-----------------------+
| ${VARIABLE-default}  | $VARIABLE    | ""                    | "default"             |
| ${VARIABLE=default}  | $VARIABLE    | ""                    | $(VARIABLE="default") |
| ${VARIABLE?default}  | $VARIABLE    | ""                    | exit 127              |
| ${VARIABLE+default}  | "default"    | "default"             | ""                    |
| ${VARIABLE:-default} | $VARIABLE    | "default"             | "default"             |
| ${VARIABLE:=default} | $VARIABLE    | $(VARIABLE="default") | $(VARIABLE="default") |
| ${VARIABLE:?default} | $VARIABLE    | exit 127              | exit 127              |
| ${VARIABLE:+default} | "default"    | ""                    | ""                    |
+----------------------+--------------+-----------------------+-----------------------+

+--------------------+----------------------------+------------------------+-----------------+
|                    | parameter Set and Not Null | parameter Set But Null | parameter Unset |
+--------------------+----------------------------+------------------------+-----------------+
| ${parameter:-word} | substitute parameter       | substitute word        | substitute word |
| ${parameter-word}  | substitute parameter       | substitute null        | substitute word |
| ${parameter:=word} | substitute parameter       | assign word            | assign word     |
| ${parameter=word}  | substitute parameter       | substitute null        | assign word     |
| ${parameter:?word} | substitute parameter       | error, exit            | error, exit     |
| ${parameter?word}  | substitute parameter       | substitute null        | error, exit     |
| ${parameter:+word} | substitute word            | substitute null        | substitute null |
| ${parameter+word}  | substitute word            | substitute word        | substitute null |
+--------------------+----------------------------+------------------------+-----------------+

${#parameter}

    String Length. The shortest decimal representation of the length in characters of the value of parameter shall be substituted. If parameter is '*' or '@', the result of the expansion is unspecified. If parameter is unset and set -u is in effect, the expansion shall fail.

The following four varieties of parameter expansion provide for character substring processing. In each case, pattern matching notation (see 2.14 Pattern Matching Notation), rather than regular expression notation, shall be used to evaluate the patterns. If parameter is '#', '*', or '@', the result of the expansion is unspecified. If parameter is unset and set -u is in effect, the expansion shall fail. Enclosing the full parameter expansion string in double-quotes shall not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces shall have this effect. In each variety, if word is omitted, the empty pattern shall be used.

${parameter%[word]}

    Remove Smallest Suffix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the smallest portion of the suffix matched by the pattern deleted. If present, word shall not begin with an unquoted '%'.

${parameter%%[word]}

    Remove Largest Suffix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the largest portion of the suffix matched by the pattern deleted.

${parameter#[word]}

    Remove Smallest Prefix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the smallest portion of the prefix matched by the pattern deleted. If present, word shall not begin with an unquoted '#'.

${parameter##[word]}

    Remove Largest Prefix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the largest portion of the prefix matched by the pattern deleted.
