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

Zan Lynx zlynx at acm.org
Wed Apr 16 11:39:04 MDT 2008


On Wed, 2008-04-16 at 11:31 -0600, Sean Reifschneider wrote:
> 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

Hey, neat.  I didn't know shell had that mode.  Since I'm a big fan of
"use strict" in Perl, I believe I'll start adding this to my shell
scripts as well.
-- 
Zan Lynx <zlynx at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20080416/b90bf4e4/attachment.pgp>


More information about the LUG mailing list