2 ms·
That colon makes no difference if the replacement is blank.
by kazinator 3y ago
That colon makes no difference if the replacement is blank.
- js2 3y agoHoly crap, 25 years of writing shell scripts and I just learned the difference: With colon, tests variable for unset or empty. Without the colon tests only for unset. It's POSIX too: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...
- kazinator 3y agoSo ${foo-bar} will not expand to bar if foo exists, but is empty. The empty value will prevail. ${foo:-bar} will expand to bar. If we have nothing in place of bar, they are effectively same.