What does $ {VARIABLE + set} mean?

I am looking at another user's code and do not know what this means. This is either a variable call to VARIABLE+set , which is a strange variable name because it has + , or it is evaluated and difficult for Google because it has $ {} in it;)

+6
source share
1 answer

Some time passed, but I found a link explaining what this does. This is a form of bash replacement that will evaluate to "set" if $VARIABLE was set and null otherwise. This allows you to check whether the variable is set by doing the following:

 if [ -z "${VARIABLE+set}" ] ; then echo "VARIABLE is not set" fi 

It is also interesting to note that ${VARIABLE+set} can also be easily ${VARIABLE+anything} . The only reason to use + set is that it is a bit more self-documenting (although this is not enough for me not to ask this question).

+7
source

Source: https://habr.com/ru/post/901077/


All Articles