3

What does +x mean in the below statement.

if[ -z ${FSV_ROOT+x} ] 
Bob Banner
  • 41
  • 1
  • 4

2 Answers2

3

Read up on Use Alternative Value. http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02

In parameter expansion if 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

Jesse
  • 1,548
  • 1
  • 17
  • 24
1

${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.

Heath Borders
  • 29,483
  • 16
  • 137
  • 246
Sam
  • 692
  • 4
  • 9