In sh, is '[' a portable synonym for 'test'?
J Q Johnson
jqj at cornell.UUCP
Sat Oct 26 23:09:25 AEST 1985
Although I personally prefer to write using [] rather than test, it has
the disadvantage of obscuring the generality of sh. After all, the
conditional can be an arbitrary list, so
if [ x = y ]; true; then echo yes; fi
prints "yes". More generally, thinking of [] as part of a special-purpose
conditional construct obscures the need for the following ";". I have
several times made the syntax error:
if [ -r whatever ] then
If I'd been using test, I wouldn't have forgotten the ";", since the
conditional would obviously have needed termination.
More information about the Comp.unix.wizards
mailing list