12

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"?

corvus_192
  • 362
  • 4
  • 15

1 Answers1

10

See PARAMETER EXPANSION in man bash:

${parameter:+word}

Use Alternate Value. If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

And few paragraphs above in the same section:

Omitting the colon results in a test only for a parameter that is unset.

choroba
  • 231,213
  • 25
  • 204
  • 289