4 ms·
Holy 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
by js2 3y ago
Holy 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.