bug-bash
[Top][All Lists]
Advanced

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

[PATCH 1/1] execute_cmd.c: don't treat rhs of = as pattern in conditiona


From: Michal Soltys
Subject: [PATCH 1/1] execute_cmd.c: don't treat rhs of = as pattern in conditional expressions
Date: Fri, 24 Aug 2012 14:54:05 +0200

In case of single '=' operator used in [[ <expression> ]], rhs argument
was treated as a pattern. Only == and != should treat rhs argument as a
pattern, so this patch fixes it.
---
 doc/bash.1    |    5 ++++-
 execute_cmd.c |    7 +++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/doc/bash.1 b/doc/bash.1
index 103d27e..e795ba9 100644
--- a/doc/bash.1
+++ b/doc/bash.1
@@ -5,7 +5,7 @@
 .\"    Case Western Reserve University
 .\"    chet@po.cwru.edu
 .\"
-.\"    Last Change: Tue Dec 28 13:41:43 EST 2010
+.\"    Last Change: Fri Aug 24 14:43:56 CEST 2012
 .\"
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
@@ -3990,6 +3990,9 @@ links and operate on the target of the link, rather than 
the link itself.
 When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
 lexicographically using the current locale.
 The \fBtest\fP command sorts using ASCII ordering.
+Furthermore, \fB[[\fP treats \fB==\fP and \fB!=\fP specially \- the rhs
+argument is interpreted as a pattern (unless it's quoted). Please see \fB[[\fP
+expression \fB]]\fP under \fB"Compound Commands"\fP for more details.
 .sp 1
 .PD 0
 .TP
diff --git a/execute_cmd.c b/execute_cmd.c
index 7432c85..fa6de84 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -3378,9 +3378,8 @@ execute_cond_node (cond)
   else if (cond->type == COND_BINARY)
     {
       rmatch = 0;
-      patmatch = ((cond->op->word[1] == '=') && (cond->op->word[2] == '\0') &&
-                 (cond->op->word[0] == '!' || cond->op->word[0] == '=') ||
-                 (cond->op->word[0] == '=' && cond->op->word[1] == '\0'));
+      patmatch = ((cond->op->word[0] == '!' || cond->op->word[0] == '=') &&
+                  cond->op->word[1] == '=' && cond->op->word[2] == '\0');
 #if defined (COND_REGEXP)
       rmatch = (cond->op->word[0] == '=' && cond->op->word[1] == '~' &&
                cond->op->word[2] == '\0');
@@ -3421,7 +3420,7 @@ execute_cond_node (cond)
          int oe;
          oe = extended_glob;
          extended_glob = 1;
-         result = binary_test (cond->op->word, arg1, arg2, 
TEST_PATMATCH|TEST_ARITHEXP|TEST_LOCALE)
+         result = binary_test (cond->op->word, arg1, arg2, (patmatch ? 
TEST_PATMATCH : 0)|TEST_ARITHEXP|TEST_LOCALE)
                                  ? EXECUTION_SUCCESS
                                  : EXECUTION_FAILURE;
          extended_glob = oe;
-- 
1.7.10.4




reply via email to

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