[lug] What the heck can I use ${VAR:-} for?

Sean Reifschneider jafo at tummy.com
Wed Apr 16 11:31:10 MDT 2008


Jeffrey Haemer wrote:
 >    if [ "${BOOTUP:-}" != "verbose" ]; then
 >
 > What's this mean?  Specifically, why's it different from this?
 >
 >    if [ "$BOOTUP" != "verbose" ]; then

There is a mode you can run the shell in, which is off by default, in which
referencing an unset variable is an error.  The default is that accessing
an unset variable results in an empty string.  So, if this mode is set,
doing:

    [ "$BOOTUP" != verbose ] && echo true

will result in an error.  Where:

    [ "${BOOTUP:-}" != verbose ] && echo true

will not.

Sean
-- 
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability



More information about the LUG mailing list