[Wylug-help] Setting Default Variables in Shell Scripts
Smylers
Smylers at stripey.com
Thu Jun 7 12:14:42 BST 2007
Hi. I've got a (Bourne) shell script which contains something along the
lines of:
: ${NAME=Seymour}
When run (on Bash) this seems to be doing the same as[*0]:
if [ -z $NAME ]
then
NAME=Seymour
fi
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?
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.
Thanks.
Smylers
[*0] Or, for anybody who knows Perl, it's the Shell equivalent of the
Perl idiom:
$name ||= 'Seymour';
More information about the Wylug-help
mailing list