From 9bd8cdf2ecc2b60f873b393122b19985cbc4587c Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Mon, 2 Jun 2025 12:15:47 +0200 Subject: vault backup: 2025-06-02 12:15:47 --- Null substitution.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Null substitution.md (limited to 'Null substitution.md') 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 -- cgit v1.2.3