bug-coreutils
[Top][All Lists]
Advanced

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

bug#8263: [PATCH] Allow == as synonym for = in test


From: David A. Wheeler
Subject: bug#8263: [PATCH] Allow == as synonym for = in test
Date: Tue, 15 Mar 2011 19:39:09 -0400 (EDT)

The following trivial patch makes GNU coreutils' test recognize "=="
as a synonym for "=".  This is already the case in GNU coreutils' expr,
bash, ksh, busybox ash, FreeBSD-current /bin/sh and /bin/test, and
OpenBSD's /bin/sh.  These are only a few lines, so I don't think
any paperwork is needed.  The following implements "==" and documents it.

  --- David A. Wheeler


--- ./src/test.c.orig   2011-03-15 00:49:11.000000000 -0400
+++ ./src/test.c        2011-03-15 09:11:04.000000000 -0400
@@ -173,7 +173,8 @@
 static bool
 binop (char const *s)
 {
-  return ((STREQ (s,   "=")) || (STREQ (s,  "!=")) || (STREQ (s, "-nt")) ||
+  return ((STREQ (s,   "=")) || (STREQ (s,  "!=")) || (STREQ (s, "==")) ||
+          (STREQ (s,   "-nt")) ||
           (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
           (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
           (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
@@ -360,7 +361,8 @@
       test_syntax_error (_("unknown binary operator"), argv[op]);
     }
 
-  if (argv[op][0] == '=' && !argv[op][1])
+  if (argv[op][0] == '=' && (!argv[op][1] ||
+       ((argv[op][1] == '=') && !argv[op][2])))
     {
       bool value = STREQ (argv[pos], argv[pos + 2]);
       pos += 3;


--- ./doc/coreutils.texi.orig   2011-03-15 00:49:10.000000000 -0400
+++ ./doc/coreutils.texi        2011-03-15 20:10:44.000000000 -0400
@@ -11535,7 +11535,7 @@
 * File type tests::             -[bcdfhLpSt]
 * Access permission tests::     -[gkruwxOG]
 * File characteristic tests::   -e -s -nt -ot -ef
-* String tests::                -z -n = !=
+* String tests::                -z -n = == !=
 * Numeric tests::               -eq -ne -lt -le -gt -ge
 * Connectives for test::        ! -a -o
 @end menu
@@ -11726,6 +11726,11 @@
 @cindex equal string check
 True if the strings are equal.
 
address@hidden @var{string1} == @var{string2}
address@hidden ==
address@hidden equal string check
+True if the strings are equal (synonym for =).
+
 @item @var{string1} != @var{string2}
 @opindex !=
 @cindex not-equal string check







reply via email to

[Prev in Thread] Current Thread [Next in Thread]