Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site oracle.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!petsd!pesnta!hplabs!oracle!abbajay
From: abbajay@oracle.UUCP (Dave Abbajay)
Newsgroups: net.unix-wizards
Subject: Re: Re: In sh, is '[' a portable synonym
Message-ID: <132@oracle.UUCP>
Date: Fri, 25-Oct-85 15:36:49 EDT
Article-I.D.: oracle.132
Posted: Fri Oct 25 15:36:49 1985
Date-Received: Sat, 26-Oct-85 19:42:36 EDT
References: <313@bdaemon.UUCP> <13400016@mirror.UUCP>
Organization: ORACLE Corporation, 2710 Sand Hill Rd., Menlo Park, CA 94025
Lines: 47
Summary: Counter arguments for test vs '[]'

In article <13400016@mirror.UUCP>, rs@mirror.UUCP writes:
> 
> /* Written 10:57 am  Oct 15, 1985 by carl@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 [  ]" 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 + 
> vs.
> 	if [ -f "$1" ]	<= 14 keystrokes + 
> 
> Which is more readable? Note that the spaces around [] are MANDATORY.
> 
> Carl Brandauer
> /* End of text from mirror:net.unix-wizar */

I also have no REAL arguments against Guy's comments save one. '/bin/test'
is a *program* and '[]' is intrepreted by the shell in all Sys III (and
greater) Bourne shells. This could have significant impact on shell script
performance, obviously, especially where loops are concerned. I was not
aware that a link between /bin/test and /bin/[ would make the '[]'
construct work in shells where '[]' was not supported! In my way of thinking,
this makes '[]' even MORE desirable for portability reasons (if the
link can be made on the target machine) as then you only pay the additional
overhead of the 'execs' of "test\[" on those machines where the shell doesn't
support '[]'.

And saving a keystroke for every test condition can be a desirable thing to
do, especially with some of the shell scripts I've written :-).


-- 
Dave Abbajay
Senior Technical Staff
ORACLE Corporation
(415)854-7350                                    hplabs!oracle!abbajay