1 year ago

#304191

test-img

asachet

Meaning of "+x" in shell parameter expansion [ -z ${FILE+x}]

I am reading some bash code and I can't figure out what the "+x" modifier does in the if condition below.

I have read the doc about parameter expansion and about if [-z ..] but this +x perplexes me. In fact, there isn't a single occurrence of "+x" in the whole bash manual (pdf)...

The code is supposed to check if the PASS environment variable is empty. If it is, it sets it to a random password.

if [ -z "${PASS+x}" ] ; then 
             PASS=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
             echo "Password set to: $PASS"
         fi;

bash

shell

parameter-expansion

0 Answers

Your Answer

Accepted video resources