[Wylug-help] Setting Default Variables in Shell Scripts

Aaron Crane wylug at aaroncrane.co.uk
Thu Jun 7 12:36:10 BST 2007


Smylers writes:
> Where is this documented?  In bash(1) searching for 'Assign Default
> Values' suggests that this variant would work:
> 
>   : ${NAME:=Seymour}
> 
> -- and indeed it does.  But how come it also works without the (second)
> colon?

Scroll back a few lines from that point in bash(1), and you find this note:

  When not performing substring expansion, bash tests for a parameter that is
  unset or null; omitting the colon results in a test only for a parameter
  that is unset.

> The script in question runs /bin/sh, not Bash specifically, so I'm
> presuming this is an old Bourne feature and not a Bash-ism.

Yes; it dates back to the earliest days of the Bourne shell.

-- 
Aaron Crane



More information about the Wylug-help mailing list