GNU bug report logs - #8263
[PATCH] Allow == as synonym for = in test

Previous Next

Package: coreutils;

Reported by: dwheeler <at> dwheeler.com

Date: Tue, 15 Mar 2011 23:41:01 UTC

Severity: normal

Tags: patch

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8263 in the body.
You can then email your comments to 8263 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#8263; Package coreutils. (Tue, 15 Mar 2011 23:41:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to dwheeler <at> dwheeler.com:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 15 Mar 2011 23:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "David A. Wheeler" <dwheeler <at> dwheeler.com>
To: bug-coreutils <at> gnu.org
Subject: [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.
 
+@item @var{string1} == @var{string2}
+@opindex ==
+@cindex equal string check
+True if the strings are equal (synonym for =).
+
 @item @var{string1} != @var{string2}
 @opindex !=
 @cindex not-equal string check






Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#8263; Package coreutils. (Mon, 21 Mar 2011 12:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 8263 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: dwheeler <at> dwheeler.com
Cc: 8263 <at> debbugs.gnu.org
Subject: Re: bug#8263: [PATCH] Allow == as synonym for = in test
Date: Mon, 21 Mar 2011 12:25:38 +0000
On 15/03/11 23:39, David A. Wheeler wrote:
> 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.

Related http://austingroupbugs.net/view.php?id=375
I'm leaning towards accepting this.

Note dash does not support ==, nor does older busybox ash.
dash seem to be waiting for the POSIX acceptance before changing?

cheers,
Pádraig.




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#8263; Package coreutils. (Mon, 21 Mar 2011 13:15:02 GMT) Full text and rfc822 format available.

Message #11 received at 8263 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: dwheeler <at> dwheeler.com, 8263 <at> debbugs.gnu.org
Subject: Re: bug#8263: [PATCH] Allow == as synonym for = in test
Date: Mon, 21 Mar 2011 07:14:14 -0600
[Message part 1 (text/plain, inline)]
On 03/21/2011 06:25 AM, Pádraig Brady wrote:
> On 15/03/11 23:39, David A. Wheeler wrote:
>> 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.
> 
> Related http://austingroupbugs.net/view.php?id=375
> I'm leaning towards accepting this.
> 
> Note dash does not support ==, nor does older busybox ash.
> dash seem to be waiting for the POSIX acceptance before changing?

Yes, that's my read of the similar thread on the dash list - dash is
waiting for the Austin Group ruling to take place first.  But coreutils
already has several extensions not in dash (it's closer to bash), so we
might as well go with it now.  I'm in favor of this patch.

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Reply sent to Jim Meyering <jim <at> meyering.net>:
You have taken responsibility. (Tue, 22 Mar 2011 06:16:01 GMT) Full text and rfc822 format available.

Notification sent to dwheeler <at> dwheeler.com:
bug acknowledged by developer. (Tue, 22 Mar 2011 06:16:01 GMT) Full text and rfc822 format available.

Message #16 received at 8263-done <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Eric Blake <eblake <at> redhat.com>
Cc: dwheeler <at> dwheeler.com, Pádraig Brady <P <at> draigBrady.com>,
	8263-done <at> debbugs.gnu.org
Subject: Re: bug#8263: [PATCH] Allow == as synonym for = in test
Date: Tue, 22 Mar 2011 07:15:16 +0100
Eric Blake wrote:
> On 03/21/2011 06:25 AM, Pádraig Brady wrote:
>> On 15/03/11 23:39, David A. Wheeler wrote:
>>> 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.
>>
>> Related http://austingroupbugs.net/view.php?id=375
>> I'm leaning towards accepting this.
>>
>> Note dash does not support ==, nor does older busybox ash.
>> dash seem to be waiting for the POSIX acceptance before changing?
>
> Yes, that's my read of the similar thread on the dash list - dash is
> waiting for the Austin Group ruling to take place first.  But coreutils
> already has several extensions not in dash (it's closer to bash), so we
> might as well go with it now.  I'm in favor of this patch.

I agree.
Here are three c-sets I expect to push later today:
  - David's patch with an adjusted log message
  - NEWS+test
  - gnulib update (unrelated)

I'm closing this ticket, too.

From 3f31ec950b78309a0d12d92d87a735b8870a2289 Mon Sep 17 00:00:00 2001
From: David A. Wheeler <dwheeler <at> dwheeler.com>
Date: Tue, 22 Mar 2011 06:03:55 +0100
Subject: [PATCH 1/3] test: accept "==" as a synonym for "="

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

Before, env test a '==' a would fail with this diagnostic:
"test: ==: binary operator expected".  Now, it succeeds.
* src/test.c: Accept "==" as a synonym for "=".
* doc/coreutils.texi (String tests): Document it.
Reported as http://debbugs.gnu.org/8263
Also see http://austingroupbugs.net/view.php?id=375
---
 doc/coreutils.texi |    7 ++++++-
 src/test.c         |    6 ++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 8dd1ed8..46deeed 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -11535,7 +11535,7 @@ test invocation
 * 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 @@ String tests
 @cindex equal string check
 True if the strings are equal.

+@item @var{string1} == @var{string2}
+@opindex ==
+@cindex equal string check
+True if the strings are equal (synonym for =).
+
 @item @var{string1} != @var{string2}
 @opindex !=
 @cindex not-equal string check
diff --git a/src/test.c b/src/test.c
index 2d7aa67..362df65 100644
--- a/src/test.c
+++ b/src/test.c
@@ -173,7 +173,8 @@ get_mtime (char const *filename, struct timespec *mtime)
 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 @@ binary_operator (bool l_is_l)
       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;
--
1.7.4.1.514.ga171c


From b3f6b33e4b31667b9b43708730f6f75f25e8ff57 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering <at> redhat.com>
Date: Tue, 22 Mar 2011 06:07:35 +0100
Subject: [PATCH 2/3] tests: exercise tests new "==" operator

* tests/misc/test: Exercise the new operator.
* NEWS (Changes in behavior): Mention it.
---
 NEWS            |    4 ++++
 tests/misc/test |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 9ceaa06..b2674c0 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   which will discard any cache associated with the files, or
   processed portion thereof.

+** Changes in behavior
+
+  test now accepts "==" as a synonym for "="
+

 * Noteworthy changes in release 8.10 (2011-02-04) [stable]

diff --git a/tests/misc/test b/tests/misc/test
index 396660b..f515b7f 100755
--- a/tests/misc/test
+++ b/tests/misc/test
@@ -132,6 +132,8 @@ my @Tests =

   ['streq-1', qw(t = t)],
   ['streq-2', qw(t = f), {EXIT=>1}],
+  ['streqeq-1', qw(t == t)],
+  ['streqeq-2', qw(t == f), {EXIT=>1}],
   ['streq-3', qw(! = !)],
   ['streq-4', qw(= = =)],
   ['streq-5', "'(' = '('"],
--
1.7.4.1.514.ga171c


From 437fcf713c237f45f9504bb8bdc6041f65663b36 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering <at> redhat.com>
Date: Tue, 22 Mar 2011 06:09:06 +0100
Subject: [PATCH 3/3] build: update gnulib submodule to latest

---
 gnulib |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gnulib b/gnulib
index 0baae9c..1a22d91 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 0baae9cadd08c9704e3c704dd69fb75640293e9d
+Subproject commit 1a22d910adea20751cc5649b224574d07ba72815
--
1.7.4.1.514.ga171c




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 19 Apr 2011 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 227 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.