test vs. [

Brandon Allbery allbery at ncoast.UUCP
Mon Oct 28 09:53:34 AEST 1985


Expires:

Quoted from <2000031 at ccvaxa> ["Re: In sh, is '[' a portable synony"], by preece at ccvaxa.UUCP...
+---------------
| > 	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.
+---------------

In general, when I am using the math/binary ops I use [, but when I want to
use the file predicates I use test.  Thus:

	if [ $expr -gt 5 ]; then

but

	if test -s /tmp/toMl$$; then

-- 
	``Youth, you are guilty of muddy thinking.''

	Mentor

ncoast!allbery at Case.CSNet (ncoast!allbery%Case.CSNet at CSNet-Relay.ARPA)
..decvax!cwruecmp!ncoast!bsa -- maybe ..genrad!mit-eddie!futura!ncoast!allbery
6615 Center St., Mentor, OH 44060 (I moved) --Phone: +01 216 974 9210
CIS 74106,1032 -- MCI MAIL BALLBERY (WARNING: I am only a part-time denizen...)
		    ncoast is dead, long live ncoast!



More information about the Comp.unix.wizards mailing list