diff options
Diffstat (limited to 'Null substitution.md')
-rw-r--r-- | Null substitution.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Null substitution.md b/Null substitution.md new file mode 100644 index 0000000..276a2e6 --- /dev/null +++ b/Null substitution.md @@ -0,0 +1,25 @@ +--- +tags: + - bash +--- +[[Bash]] [[Process substition (tmp file)]] [[Parameter subsitution]] + +--- +[This](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02) page contains a table with [[Parameter subsitution]] + +When we want to expand a variable into an argument to a command but the variable is empty it will expand to **an empty string**. This is often unwanted, we just want `null` which is removed from the command-line. + +*Example* +``` +openstack server delete server "${waitFlag}" +``` +if `waitFlag` is empty this will become: +``` +openstack server delete server '' +``` +which results in an error. + +This is where we can use `null substitution`: +``` +openstack server delete server "${waitFlag:+$waitFlag}" +```
\ No newline at end of file |