3 ms·
If you already assume bash, then you don’t need the “-v” option to the “test” builtin; just do if [ "${foo+some_string}" = "" ]; then echo "foo is unset"
by teddyh 4y ago
If you already assume bash, then you don’t need the “-v” option to the “test” builtin; just do
if [ "${foo+some_string}" = "" ]; then
echo "foo is unset"
fi
or, in your case:
if test "${2+x}" = "" # i.e. if $2 is not set
- tpoacher 4y agoTrue, but I consider this very hacky, error-prone, and unnecessary when a clear, bespoke test flag exists. Also, if you prefer the "[ ... ]" syntax for testing, then you can use `-v` directly anyway (since that is equivalent to the builtin test keyword anyway).
- hddqsb 4y agoIn fact `${foo+some_string}` is supported by POSIX sh (unlike `test -v`).