Why parse lines with colons
Yehoyaqim Martillo
martillo at ihuxt.UUCP
Fri Jul 13 03:07:51 AEST 1984
>One of the reasons /bin/sh (bsh to those who like csh)
>parses lines with ":" in the beginning is because of
>constructs like the following:
>: ${FOO:-default}
>This effectively sets $FOO to a default value if not previously
>set.
According to my shell manual the value of this expression is $FOO is FOO
is set and not not null otherwise, the value is default. The value of FOO
does not change. I believe he means
: ${FOO:=default}
>The longhand way would be:
>if [ "${FOO}" = "" ]
>then
> FOO=default
>fi
He could just as well have used:
FOO=${FOO:-default}
which avoids the ":" and takes hardly any (and probably no) more time to
execute.
--
Who wouldn't break for whales?
Yehoyaqim Shemtob Martillo
More information about the Comp.unix.wizards
mailing list