Synopsis: [PATCH] Modify test/[ to support ==, making it consistent with
/bin/sh
Category:
Environment: OpenBSD 4.8 (GENERIC) -current

Description:
  /bin/sh's built-in implementation of "test/[" supports "==" (string
equality),
  but /bin/test does not.  That's an odd inconsistency, and many scripts use
"==".

  The following patch modifies "test/[" so that it ALSO supports "==".

How-to-Repeat:
  When running /bin/sh:
  test a == a && echo hi         # prints hi
  /bin/test a == a && echo hi  # prints test: ==: unknown operand.  Weird
inconsistency.

Fix:
Here's a (trivial) patch; cd /usr/src/bin/test and run "patch" on this.
The code patch is only 1 line long, but I wanted to make sure the
documentation
is up-to-date too:


? ksh.core
? man
? ssh.core
? test
Index: test.1
===================================================================
RCS file: /cvs/src/bin/test/test.1,v
retrieving revision 1.30
diff -u test.1
--- test.1      11 Sep 2010 20:54:22 -0000      1.30
+++ test.1      12 Mar 2011 18:27:56 -0000
@@ -199,6 +199,12 @@
 and
 .Ar s2
 are identical.
+.It Ar s1 Cm == Ar s2
+True if the strings
+.Ar s1
+and
+.Ar s2
+are identical (synonym for =).
 .It Ar s1 Cm != Ar s2
 True if the strings
 .Ar s1
@@ -332,6 +338,7 @@
 .Fl nt ,
 .Fl ot ,
 .Fl ef ,
+.Cm == ,
 .Cm \*(Lt ,
 and
 .Cm \*(Gt
Index: test.c
===================================================================
RCS file: /cvs/src/bin/test/test.c,v
retrieving revision 1.11
diff -u test.c
--- test.c      27 Oct 2009 23:59:22 -0000      1.11
+++ test.c      12 Mar 2011 18:27:56 -0000
@@ -33,7 +33,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>
 */
@@ -115,6 +115,7 @@
        {"-L",  FILSYM, UNOP},
        {"-S",  FILSOCK,UNOP},
        {"=",   STREQ,  BINOP},
+       {"==",  STREQ,  BINOP},
        {"!=",  STRNE,  BINOP},
        {"<",   STRLT,  BINOP},
        {">",   STRGT,  BINOP},
? test.cat1
? test.patch





--- David A. Wheeler

Reply via email to