In sh, is '[' a portable synonym

rs at mirror.UUCP rs at mirror.UUCP
Sat Oct 19 03:37:00 AEST 1985


/* Written 10:57 am  Oct 15, 1985 by carl at bdaemon in mirror:net.unix-wizar */
/* ---------- "Re: In sh, is '[' a portable synony" ---------- */
> > 
> > 	On my 4.2bsd system, the following do the same thing in sh because
> > /bin/[ is a link to /bin/test. ... Is the "[]" form safe to use if you want
> > ....
> 
> V7 systems where /bin/[ isn't a link to /bin/test.  Any V7 or post-V7 system
> can be made to support "if [ <condition> ]" as equivalent to "if test
> .....
> 	GUy Harris

I have absolutely no arguments with Guy's message, but would like to point
out that the [ condition ] construct saves only one keystroke at the
expense of readability.  E.g.:

	if test -f "$1"	<= 15 keystrokes + <CR>
vs.
	if [ -f "$1" ]	<= 14 keystrokes + <CR>

Which is more readable? Note that the spaces around [] are MANDATORY.

Carl Brandauer
/* End of text from mirror:net.unix-wizar */



More information about the Comp.unix.wizards mailing list