We've got yet another construct called:
${param:+value} |
This construct means:
If the parameter is NULL or UNSET, then substitute nothing, otherwise substitute the value.
We might use this as follows:
OPTION=T echo ${OPTION:+"Option set to T"} |
Thus if the option is set (to anything actually), then you would see the following output:
Option set to T |
However if you unset OPTION the output would differ. Type:
unset OPTION echo ${OPTION:+"Option set to T"} |
You will get a blank line for the output. Why? Because it says if the option is set then print out the value, otherwise print out nothing.
Please don't become confused that the OPTION being set to 'T' has ANYTHING to do with the output.
For example if I set OPTION to zingzangzoom as follows:
OPTION='zingzangzoom' echo ${OPTION:+"Option set to T"} |
the outcome would still be:
Option set to T |
This construct is simply testing whether the variable has a value i.e. is NOT NULL or UNSET.
These are a couple of the standard constructs.