NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/44733: [PATCH] Have test/[ accept "==" as a synonym for "="



>Number:         44733
>Category:       bin
>Synopsis:       [PATCH] Have test/[ accept "==" as a synonym for "="
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 17 02:45:00 +0000 2011
>Originator:     David A. Wheeler
>Release:        -current
>Organization:
>Environment:
NetBSD  5.1 NetBSD 5.1 (GENERIC) #0: Sun Nov  7 14:39:56 UTC 2010  
builds%b6.netbsd.org@localhost:/home/builds/ab/netbsd-5-1-RELEASE/i386/201011061943Z-obj/home/builds/ab/netbsd-5-1-RELEASE/src/sys/arch/i386/compile/GENERIC
 i386

But really, the environment doesn't matter.
>Description:
Currently test/[ does not support "==" as a synonym for the
"=" binary operator ("are strings equal").
Although it's not in the POSIX spec, it is widely used and implemented;
"==" is accepted by FreeBSD-current /bin/sh and /bin/test,
OpenBSD's /bin/sh, bash, ksh, and busybox ash.

The included patch adds support for "==" in test/[.

>How-To-Repeat:
Running:
 /bin/test a == a && echo hi
should print "hi".
Currently it prints test: ==: unexpected operator

Running:
 [ a == a ] && echo hi
should print "hi".
Currently it prints [: ==: unexpected operator



>Fix:
--- test.c.orig 2008-09-10 19:00:51.000000000 +0000
+++ test.c      2011-03-15 22:43:50.000000000 +0000
@@ -41,7 +41,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>
 */
@@ -113,6 +113,7 @@
 
 static const struct t_op cop2[] = {
        {"!=",  STRNE,  BINOP},
+       {"==",  STREQ,  BINOP},
 };
 
 static const struct t_op mop3[] = {
@@ -623,6 +624,8 @@
                            compare1);
                else if (strcmp(s, cop2[0].op_text) == 0)
                        return cop2;
+               else if (strcmp(s, cop2[1].op_text) == 0)
+                       return &(cop2[1]);
                else
                        return NULL;
        }


--- test.1.orig 2009-11-10 18:19:46.000000000 +0000
+++ test.1      2011-03-15 20:19:17.000000000 +0000
@@ -200,6 +200,12 @@
 and
 .Ar \&s\&2
 are identical.
+.It Ar \&s\&1 Cm \&== Ar \&s\&2
+True if the strings
+.Ar \&s\&1
+and
+.Ar \&s\&2
+are identical (synonym of =).
 .It Ar \&s\&1 Cm \&!= Ar \&s\&2
 True if the strings
 .Ar \&s\&1



Home | Main Index | Thread Index | Old Index