What does +x mean in the below statement?
if[ -z ${FSV_ROOT+x} ]
What does +x mean in the below statement?
if[ -z ${FSV_ROOT+x} ]
Read up on Use Alternative Value. See 2.6.2 Parameter Expansion.
In parameter expansion, if a parameter is unset or null, null shall be substituted; otherwise, the expansion of word shall be substituted. Use of the colon in the format shall result in a test for a parameter that is unset or null; omission of the colon shall result in a test for a parameter that is only unset.
So in your case:
If FSV_ROOT is set and not null, substitute x
If FSV_ROOT set but null, substitute x
If FSV_ROOT is unset, substitute null
${parameter+alt_value}
: if parameter is set (to any value including null), return "alt_value" instead.
[ -z ${parameter+x} ]
will return true if parameter has not been set at all. The "x" has no special meaning and could be replaced with any non-null string. It is there primarily because just [ -z $parameter ]
would also return true if parameter were set to null - but it also helps to avoid a syntax error if $parameter were set to expand to more than one word, which would require quoting of the variable otherwise.
See also: https://tldp.org/LDP/abs/html/parameter-substitution.html#PARAMALTV http://tldp.org/LDP/abs/html/refcards.html
Do not confuse with the common use of +x with the chmod
command, where it means to set the execute bit on a file.