Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/17/84; site bdaemon.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!hao!nbires!bdaemon!carl
From: carl@bdaemon.UUCP (carl)
Newsgroups: net.unix-wizards
Subject: Re: In sh, is '[' a portable synonym for 'test'?
Message-ID: <314@bdaemon.UUCP>
Date: Thu, 24-Oct-85 12:47:10 EDT
Article-I.D.: bdaemon.314
Posted: Thu Oct 24 12:47:10 1985
Date-Received: Sat, 26-Oct-85 04:23:09 EDT
References: <482@phri.UUCP> <2887@sun.uucp> <313@bdaemon.UUCP> <2908@sun.uucp>
Distribution: net
Organization: Daemon Assoc., Boulder, CO
Lines: 36

> > 	if test -f "$1"	<= 15 keystrokes + 
> > vs.
> > 	if [ -f "$1" ]	<= 14 keystrokes + 
> > 
> > Which is more readable?
> 
> The latter, obviously; it reads more like a conditional statement rather
> than a command.

Hogwash.  The manual states

	if *list* then *list* [ elif *list* then *list* ] ...

where *list* is defined  as a sequence on one or more pipelines ,i.e
commands. *Test* is a command like any other, so why should it be treated
any differently?

> It may be *implemented* as a command (which, if the command
> isn't builtin, slows it down - somebody who complained that "test" shouldn't
> be built in was later seen using a "case" statement instead of an "if" and a
> "test" in order to make it run faster), but that fact isn't relevant to
> understanding what it *does*.

Agreed, irrelevant to the present discussion.

> Good grief, do you think that people use the square bracket to save one
> measly keystroke?  That's not why it's there - it's there to improve the
> readability of the statement.
> 
> 	Guy Harris

Yes, but only by people who want to obscure the fact that "if tests the
value returned by the last simple command following it" (S. R. Bourne,
The UNIX System, page 58).

Carl Brandauer