In sh, is '[' a portable synonym

Larry West west at sdcsla.UUCP
Wed Oct 30 08:43:52 AEST 1985


>  
>  	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.

I don't really know which is more readable (though I wonder
why the author was confusing this with the number of keystrokes
-- redundancy often aids readability, and in particular the
spaces around [] are helpful).

However, I would like to point out that users have a habit
of naming programs "test", and of having "/bin" occur late
in their paths.   This tends to cause confusion because the
problem (as usual) doesn't come up until that brief "test"
program has been forgotten.

So, my suggestion is to always use "/bin/test" instead
of simply "test", or else use "[ ]".   I know, fixing the
the particular pathname of a program is a bad idea, but this
seems a fairly safe case (unless you plan to provide an
improved user interface to "test":-).
-- 

Larry West				(USA+619-)452-6771
Institute for Cognitive Science		non-business hours: 452-2256
UC San Diego (mailcode C-015)
La Jolla, CA  92093  U.S.A.

ARPA:	<west at nprdc.ARPA>	or	<west at ucsd.ARPA>
UUCP:	{ucbvax,sdcrdcf,decvax,ihnp4}!sdcsvax!sdcsla!west
  or	{sun,mplvax,gti,ihnss,whuxlb,ulysses}!sdcsla!west



More information about the Comp.unix.wizards mailing list