Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 exptools; site whuxl.UUCP
Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!whuxl!mike
From: mike@whuxl.UUCP (BALDWIN)
Newsgroups: net.unix-wizards
Subject: Re: In sh, is '[' a portable synonym for 'test'?
Message-ID: <743@whuxl.UUCP>
Date: Fri, 25-Oct-85 23:38:01 EDT
Article-I.D.: whuxl.743
Posted: Fri Oct 25 23:38:01 1985
Date-Received: Sat, 26-Oct-85 19:16:29 EDT
References: <482@phri.UUCP> <2887@sun.uucp> <313@bdaemon.UUCP> <2908@sun.uucp> <314@bdaemon.UUCP>
Distribution: net
Organization: AT&T Bell Laboratories, Whippany
Lines: 45

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

Who cares WHAT [ or test really are?  I *like* if statements to look like if
statement, thank you.
	if [ $x = 3 ]
is more pleasing AND READABLE to me than
	if test $x = 3

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

Oh, bushwah!  I don't want to obscure what the if stmt does, I want to
make it LESS obscure.  If you ask me, "if test expr" is obscuring the
fact that this is a simple conditional, whereas "if [ expr ]" is obvious.

Speaking of test, is anyone else out there annoyed that there really
isn't a good way to deal with strings?  Instead of nice and simple
[ "$x" = foo ] you have to say [ "X$x" = Xfoo ] which is kinda ugly.
Also, [ -n "$x" ] is right out (what if x is "="?), along with -z.
Expr has the same problem with "expr string : regexp".  Bleah!
-- 
						Michael Baldwin
						{at&t}!whuxl!mike