What does ${ARGUMENT+x} mean in Bash? [duplicate]
Solution 1:
It means that if $ARGUMENT
is set, it will be replaced by the string x
Let's try in a shell :
$ echo ${ARGUMENT+x}
$ ARGUMENT=123
$ echo ${ARGUMENT+x}
x
You can write this with this form too :
${ARGUMENT:+x}
It have a special meaning with :
, it test that variable is empty or unset
Check bash parameter expansion
Solution 2:
Rather than discussing the syntax, I'll point out what it is attempting to do: it is trying to deterimine if a variable ARGUMENT
is set to any value (empty or non-empty) or not. In bash
4.3 or later, one would use the -v
operator instead:
if [[ -v ARGUMENT ]]; then