In sh, is '[' a portable synony

preece at ccvaxa.UUCP preece at ccvaxa.UUCP
Tue Oct 22 03:06:00 AEST 1985


> ... 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.
> /* Written  9:57 am  Oct 15, 1985 by carl at bdaemon.UUCP in
> ccvaxa:net.unix-wizards */
----------
Well, readability is very much in the eye of the beholder.  I much
prefer the second form, which I gather you think is less readable.
The test part is bracketed.  The syntax is closer to C.  The word
"test" has been turned into a symbol, which is generally a good thing
[flamers please note and respect that "generally"].

Now, if you wanted to substitute words for the test names, I'd be
right with you.  "-f" doesn't suggest anything to me...

-- 
scott preece
gould/csd - urbana
ihnp4!uiucdcs!ccvaxa!preece



More information about the Comp.unix.wizards mailing list