next up previous contents
Next: Arithmetic expressions using variables Up: Variables Previous: Special variables   Contents

Unset variables

You can test to see if a variable is not defined, or is set to a null string for example the construction:-

${var-word}

returns the value of var if defined otherwise it returns the value of word:-

>  unset var
>  echo "${var-jim}"
jim
>  var="fred"
>  echo "${var-jim}"
fred

Similar constructions:-

${var=word} If var unset, set it equal to word then return var
${var+word} if var unset return nothing otherwise return word
${var?word} if var unset print word to standard error and exit.
 



P.D. Gronbech (IT Staff) 2015-10-02