Update bash.md

This commit is contained in:
Rico Sta. Cruz 2020-06-13 10:11:51 +10:00 committed by GitHub
parent 0361fa173b
commit bf22b55008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

14
bash.md
View File

@ -1,4 +1,4 @@
(--- ---
title: Bash scripting title: Bash scripting
category: CLI category: CLI
layout: 2017/sheet layout: 2017/sheet
@ -211,17 +211,17 @@ echo ${STR^} #=> "Hello world!" (uppercase 1st letter)
echo ${STR^^} #=> "HELLO WORLD!" (all uppercase) echo ${STR^^} #=> "HELLO WORLD!" (all uppercase)
``` ```
### Default values ### Default values
| `${FOO:-val}` | `$FOO`, or `val` if unset (or null) | | Expression | Description |
| `${FOO:=val}` | Set `$FOO` to `val` if unset (or null) | | ----------------- | -------------------------------------------------------- |
| `${FOO:+val}` | `val` if `$FOO` is set (and not null) | | `${FOO:-val}` | `$FOO`, or `val` if unset (or null) |
| `${FOO:?message}` | Show error message and exit if `$FOO` is 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`. Omitting the `:` removes the (non)nullity checks, e.g. `${FOO-val}` expands to `val` if unset otherwise `$FOO`.
Loops Loops
----- -----
{: .-three-column} {: .-three-column}