From 7a2322761a4fc47cb13da87219857e08c99afc05 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 20 Apr 2020 10:19:52 +0000 Subject: [PATCH] Fix nullity checks for parameter expansion --- bash.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bash.md b/bash.md index 001186ee6..40ed7d768 100644 --- a/bash.md +++ b/bash.md @@ -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 -----