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

'command -pv zsh' => 'zsh: command not found: -pv'



Actual behaviour:
t1% command -pv zsh
zsh: command not found: -pv

Expected behaviour:
Look for a 'zsh' executable in the default $PATH and print its path.
(i.e., print '/usr/local/bin/zsh'.)

Environment:
t1% zsh -f
t1% echo $ZSH_VERSION
4.3.10

Mikael Magnusson reported on IRC that he can reproduce that locally,
using a more recent zsh.

---

Looking into the cause, I guess that it's due to this bit of argument
parsing in ./Src/exec.c:2433:

[[[
	    if ((cflags & BINF_COMMAND) && nextnode(firstnode(args))) {
		/* check for options to command builtin */
		char *next = (char *) getdata(nextnode(firstnode(args)));
		char *cmdopt;
		if (next && *next == '-' && strlen(next) == 2 &&
		        (cmdopt = strchr("pvV", next[1])))
		{
		    if (*cmdopt == 'p') {
]]]

I've looked into converting that parsing to a while() loop (as used by
other if() blocks in the vicinity), but haven't got a working patch yet
and didn't want to delay this email until I did.
diff --git Src/exec.c Src/exec.c
index f5b59a3..cc1682d 100644
--- Src/exec.c
+++ Src/exec.c
@@ -2433,22 +2433,31 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		/* check for options to command builtin */
 		char *next = (char *) getdata(nextnode(firstnode(args)));
 		char *cmdopt;
-		if (next && *next == '-' && strlen(next) == 2 &&
-		        (cmdopt = strchr("pvV", next[1])))
-		{
-		    if (*cmdopt == 'p') {
-			uremnode(args, firstnode(args));
-			use_defpath = 1;
-			if (nextnode(firstnode(args)))
-			    next = (char *) getdata(nextnode(firstnode(args)));
-		    } else {
-			hn = &commandbn.node;
-			is_builtin = 1;
+		while (next && *next == '-' && strlen(next) >= 2) {
+		    uremnode(args, firstnode(args));
+		    if (!strcmp(next, "--"))
 			break;
+		    for (cmdopt = &next[1]; *cmdopt; ++cmdopt) {
+			switch (*cmdopt) {
+			case 'p':
+			    use_defpath = 1;
+			    break;
+			case 'v':
+			case 'V':
+			    is_builtin = 1;
+			    break;
+			default:
+			    zerr("unknown command flag -%c", *cmdopt);
+			    errflag = lastval = 1;
+			    return;
+			}
 		    }
+		    next = (char *) getdata(nextnode(firstnode(args)));
+		}
+		if (is_builtin) {
+		    hn = &commandbn.node;
+		    break;
 		}
-		if (!strcmp(next, "--"))
-		     uremnode(args, firstnode(args));
 	    }
 	    if ((cflags & BINF_EXEC) && nextnode(firstnode(args))) {
 		/*


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