Parameter Expansion – POSIX (bash)

                     +----------------------+-----------------+-----------------+
                     |       parameter      |    parameter    |    parameter    |
                     |   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 |
+--------------------+----------------------+-----------------+-----------------+

source: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

Leave a comment

Your comment