9

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
  • 322
  • 5
  • 10

1 Answers1

9

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
  • 216,930
  • 22
  • 195
  • 267