martillo@ihuxt.UUCP (Yehoyaqim Martillo) (07/12/84)
>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
dave@csu60.UUCP (07/13/84)
Maybe my shell is weird, but I had to say: FOO=${FOO:-default} The simple ": ${FOO:-default}" didn't work. I find those ":" comments useful for makefiles where I want to null out a particular operation e.g. INSTALL=":" make fred where $INSTALL normally defaults to "install".
npl@spuxll.UUCP (Nick Landsberg) (07/17/84)
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. The longhand way would be: if [ "${FOO}" = "" ] then FOO=default fi From the hairy eyeball of --- Nick Landsberg ( ....!spuxll!npl)
dan@haddock.UUCP (07/18/84)
#R:spuxll:-52600:haddock:16800020:000:593 haddock!dan Jul 16 13:59:00 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} I think you mean : ${FOO:=default} > This effectively sets $FOO to a default value if not previously > set. The longhand way would be: > if [ "${FOO}" = "" ] > then > FOO=default > fi No, the "longhand" way would be FOO=${FOO:-default} which isn't very much longer, and has the advantage that it works even if you set -u (which I usually do). I don't think this is a good reason to parse lines with ":". Dan Franklin