Bash – What does the expression ${MYVAR:+-x} mean in bash

bashshellvariable substitution

In a bash script I cannot post here I see the following expression:

${MYVAR:+-x}

I understand the meaning of expressions like ${MYVAR:+OTHERVAR} and ${MYVAR:-OTHERVAR}, but an expression with both a plus-sign and a minus-sign. What does it mean, if anything?

Best Answer

This is the same as

${MYVAR:+OTHERVAR}

with OTHERVAR being equal to -x. In other words, if MYVAR is unset or null, substitute null; otherwise, substitute -x.

References

Related Question