Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: globbing in conditional expressions



On Mon, 4 Aug 2014 19:16:01 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> However,
> % [[ alpha.c = (#b)(*).c(#q.) ]]
> zsh: no matches found: (#b)(*).c(#q.)
> 
> This example no longer works.

Oh, you mean if alpha.c doesn't exist, since it's doing now globbing
rather than pattern matching.  Probably we oughtn't to be doing the
special glob thing if the argument is already being treated as a
pattern.  This could probably do with a test.

diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 8394ffc..9bff013 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -2338,7 +2338,9 @@ avoided for the sake of clarity.  Note that within conditions using the
 `tt([[)' form the presence of a parenthesised expression
 tt(LPAR()#q...+RPAR()) at the end of a string indicates that globbing
 should be performed; the expression may include glob qualifiers, but
-it is also valid if it is simply tt(LPAR()#q+RPAR()).
+it is also valid if it is simply tt(LPAR()#q+RPAR()).  This does
+not apply to the right hand side of pattern match operators as the
+syntax already has special significance.
 
 A qualifier may be any one of the following:
 
diff --git a/Src/cond.c b/Src/cond.c
index 3807409..df90656 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -297,8 +297,7 @@ evalcond(Estate state, char *fromtest)
 
 		right = dupstring(opat = ecrawstr(state->prog, state->pc,
 						  &htok));
-		if (htok)
-		    cond_subst(&right, !fromtest);
+		singsub(&right);
 		save = (!(state->prog->flags & EF_HEAP) &&
 			!strcmp(opat, right) && pprog != dummy_patprog2);
 
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index 358c934..d7a0fae 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -533,14 +533,12 @@
     cd glob.tmp
     [[ -n a*(#qN) ]] && print File beginning with a
     [[ -z z*(#qN) ]] && print No file beginning with z
-    [[ "a b c" = ?(#q) ]] && print Multiple files matched
     setopt nonomatch
     [[ -n z*(#q) ]] && print Normal string if nullglob not set
   )
 0:Force glob expansion in conditions using (#q)
 >File beginning with a
 >No file beginning with z
->Multiple files matched
 >Normal string if nullglob not set
 
  (){ print $#@ } glob.tmp/dir*(Y1)

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author