From 7a2322761a4fc47cb13da87219857e08c99afc05 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 20 Apr 2020 10:19:52 +0000 Subject: [PATCH 1/3] 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 ----- From 0361fa173bbc6e280685743e500cb1a188461110 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 20 Apr 2020 11:21:31 +0100 Subject: [PATCH 2/3] Update bash.md --- bash.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash.md b/bash.md index 40ed7d768..3f6b85efb 100644 --- a/bash.md +++ b/bash.md @@ -1,4 +1,4 @@ ---- +(--- title: Bash scripting category: CLI layout: 2017/sheet @@ -217,7 +217,7 @@ echo ${STR^^} #=> "HELLO WORLD!" (all uppercase) | `${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) | +| `${FOO:?message}` | Show error message and exit if `$FOO` is unset (or null) | Omitting the `:` removes the (non)nullity checks, e.g. `${FOO-val}` expands to `val` if unset otherwise `$FOO`. From bf22b55008d2cbf4625d22be129c4c121009bca8 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sat, 13 Jun 2020 10:11:51 +1000 Subject: [PATCH 3/3] Update bash.md --- bash.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bash.md b/bash.md index 3f6b85efb..e9bb11ff8 100644 --- a/bash.md +++ b/bash.md @@ -1,4 +1,4 @@ -(--- +--- title: Bash scripting category: CLI layout: 2017/sheet @@ -211,17 +211,17 @@ echo ${STR^} #=> "Hello world!" (uppercase 1st letter) echo ${STR^^} #=> "HELLO WORLD!" (all uppercase) ``` - ### Default values -| `${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 null) | +| Expression | Description | +| ----------------- | -------------------------------------------------------- | +| `${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 null) | Omitting the `:` removes the (non)nullity checks, e.g. `${FOO-val}` expands to `val` if unset otherwise `$FOO`. - Loops ----- {: .-three-column}