Subject: Re: test: ==: unexpected operator
To: Hubert Feyrer <hubert@feyrer.de>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-userlevel
Date: 09/21/2006 20:35:36
On Sep 21, 2006, at 5:06 PM, Hubert Feyrer wrote:
>
> bash/Linux allows "==" as an alternative to "=" in their test(1)
> command.
> I wonder if we want to save some trouble and just make our test(1)
> silently accept that too, instead of fixing all the broken scripts
> out there.
>
> It'd be an extension to POSIX, so I don't see much of a problem.
I'm OK with this. In fact, I noticed a couple of months ago at Day
Job that I actually used the Bash syntax by mistake.
If you do this, though, make sure to update any other implementations
of test (like built-ins in sh(1) / ksh(1)).
>
> Any thoughts?
>
>
> - Hubert
>
>
> Index: test.c
> ===================================================================
> RCS file: /cvsroot/src/bin/test/test.c,v
> retrieving revision 1.28
> diff -u -r1.28 test.c
> --- test.c 4 Aug 2006 19:07:55 -0000 1.28
> +++ test.c 22 Sep 2006 00:04:42 -0000
> @@ -39,7 +39,7 @@
> unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
> "-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
>
> - binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
> + binary-operator ::= "="|"=="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-
> lt"|
> "-nt"|"-ot"|"-ef";
> operand ::= <any legal UNIX file name>
> */
> @@ -121,6 +121,7 @@
> {"-L", FILSYM, UNOP},
> {"-S", FILSOCK,UNOP},
> {"=", STREQ, BINOP},
> + {"==", STREQ, BINOP}, /* bash compatibility */
> {"!=", STRNE, BINOP},
> {"<", STRLT, BINOP},
> {">", STRGT, BINOP},
>
>
> P.S.: As an alternative we could add some swearing at the user to
> use proper POSIX syntax and whatnot. I'm sure you will come up with
> something fancy. 8-)
-- thorpej