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

Re: zsh handling of non-standard if-evaluations



On Sun, 28 Jan 2007 21:57:40 +0000
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> (That seems a little strange, actually.  Either you'd expect == to find
> a programme called =, or you'd expect == to be a normal argument without
> any pattern match failure.  It seems that you need to quote the second
> argument: =\= does find = in the path.  That strikes me as a bug.)

Here's a rationalization, so that == does find = (unless NO_EQUALS is
on, obviously), and likewise for any other metacharacters that haven't
been dealt with at the time of the = expansion (note this is before
globbing---necessarily in the case of ~-expansion which is performed at
the same time as =-expansion).

However, it's very tempting to make "==" an exception (and document it)
since it's kind of intuitively obvious (if you're a geek) that "==" is a
test for equality rather than an attempt to look for a programme called
"=".  Still, POSIX doesn't give any imperative reason to do so.

(In case anyone's unclear, == in [[ ... ]] is and has always been
handled specially because zsh understands the syntax of [[ ... ]],
so it doesn't get handled as a normal command.  [ ... ] and test, on the
other hand, are ordinary builtins, hence the problem.)

Index: Src/string.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/string.c,v
retrieving revision 1.8
diff -u -r1.8 string.c
--- Src/string.c	28 Oct 2005 17:34:33 -0000	1.8
+++ Src/string.c	2 Feb 2007 21:29:26 -0000
@@ -135,7 +135,7 @@
     return ptr;
 }
 
-/* like strdup(), but with a specified length */
+/* like dupstring(), but with a specified length */
 
 /**/
 mod_export char *
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.73
diff -u -r1.73 subst.c
--- Src/subst.c	26 Jan 2007 19:18:17 -0000	1.73
+++ Src/subst.c	2 Feb 2007 21:29:27 -0000
@@ -570,21 +570,21 @@
 	    return 1;
 	}
     } else if (*str == Equals && isset(EQUALS) && str[1]) {   /* =foo */
-	char sav, *pp, *cnam;
+	char *pp, *cnam, *cmdstr, *str1 = str+1;
 
-	for (pp = str + 1; !isend2(*pp); pp++);
-	sav = *pp;
-	*pp = 0;
-	if (!(cnam = findcmd(str + 1, 1))) {
+	for (pp = str1; !isend2(*pp); pp++)
+	    ;
+	cmdstr = dupstrpfx(str1, pp-str1);
+	untokenize(cmdstr);
+	remnulargs(cmdstr);
+	if (!(cnam = findcmd(cmdstr, 1))) {
 	    if (isset(NOMATCH))
-		zerr("%s not found", str + 1);
+		zerr("%s not found", cmdstr);
 	    return 0;
 	}
 	*namptr = dupstring(cnam);
-	if (sav) {
-	    *pp = sav;
+	if (*pp)
 	    *namptr = dyncat(*namptr, pp);
-	}
 	return 1;
     }
     return 0;

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