The shell has other (neater) constructs for doing setting and checking parameters.


This means: if the parameter is UNSET or a NULL value, then substitute the value that has been set previously.

Using MAGIC, we can type:

echo ${MAGIC:-'zingzangzoom'}

which should echo:



Since MAGIC is NOT NULL, and NOT UNSET, the variable is used, thus abracadabra.

What happens if we unset the variable to give it a null value?

unset MAGIC
echo ${MAGIC:-'zingzangzoom'}

Now echo will print:


One of the places that system administrators use this is:

${EDITOR:-/bin/vi} somefile

If you haven't set your environment variable called EDITOR or it's set to a NULL value, then use the default editor vi to edit the file somefile.

If you have set EDITOR with:


then you'd use emacs to edit the file somefile.


unset $MAGIC
echo ${MAGIC:-'zingzangzoom'}
echo $MAGIC

MAGIC is not being set to 'zingzangzoom'. The :- construct is not actually setting the value of MAGIC, it's just testing the value of MAGIC.