Fix nullity checks for parameter expansion

This commit is contained in:
Angus Hollands 2020-04-20 10:19:52 +00:00
parent cb4e03077f
commit 7a2322761a
1 changed files with 6 additions and 5 deletions

11
bash.md
View File

@ -214,12 +214,13 @@ echo ${STR^^} #=> "HELLO WORLD!" (all uppercase)
### Default values
| `${FOO:-val}` | `$FOO`, or `val` if not set |
| `${FOO:=val}` | Set `$FOO` to `val` if not set |
| `${FOO:+val}` | `val` if `$FOO` is set |
| `${FOO:?message}` | Show error message and exit if `$FOO` is not set |
| `${FOO:-val}` | `$FOO`, or `val` if unset (or null) |
| `${FOO:=val}` | Set `$FOO` to `val` if unset (or null) |
| `${FOO:+val}` | `val` if `$FOO` is set (and not null) |
| `${FOO:?message}` | Show error message and exit if `$FOO` is unset (or is null) |
Omitting the `:` removes the (non)nullity checks, e.g. `${FOO-val}` expands to `val` if unset otherwise `$FOO`.
The `:` is optional (eg, `${FOO=word}` works)
Loops
-----