GNU bug report logs -
#8263
[PATCH] Allow == as synonym for = in test
Previous Next
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.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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
This bug report was last modified 14 years and 125 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.