Merge pull request #1410 from agoose77/master

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

13
bash.md
View File

@ -211,15 +211,16 @@ 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 not set | | Expression | Description |
| `${FOO:=val}` | Set `$FOO` to `val` if not set | | ----------------- | -------------------------------------------------------- |
| `${FOO:+val}` | `val` if `$FOO` is set | | `${FOO:-val}` | `$FOO`, or `val` if unset (or null) |
| `${FOO:?message}` | Show error message and exit if `$FOO` is not set | | `${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) |
The `:` is optional (eg, `${FOO=word}` works) Omitting the `:` removes the (non)nullity checks, e.g. `${FOO-val}` expands to `val` if unset otherwise `$FOO`.
Loops Loops
----- -----