I've come across code that uses this syntax in an if condition:
if [ ! -z ${VARIABLE+x} ]; then
some commands here
fi
Does it test for an non-empty variable? If so, how is it different from ! -z "$VARIABLE"
?
See PARAMETER EXPANSION in man bash
:
${parameter:+word}
Use Alternate Value. If
parameter
is null or unset, nothing is substituted, otherwise the expansion ofword
is substituted.
And few paragraphs above in the same section:
Omitting the colon results in a test only for a parameter that is unset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With