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

Re: Possibly unexpected difference between builtin and reserved typeset



On Sep 15, 11:29am, Mikael Magnusson wrote:
} Subject: Possibly unexpected difference between builtin and reserved types
}
} % foo=bar \typeset foo; echo . $foo .
} foo=bar
} . .
} % foo=bar typeset foo; echo . $foo .
} foo=bar
} . bar .
} 
} Out of the ones I tried in $reswords, typeset and friends seem to be
} the only ones that aren't a syntax error after parameter assignments,
} so I guess that might be why the code doesn't handle it?

This is related to the "x=2 | ..." problem discussed in another thread,
but easier to fix.

I think the following does the right thing WRT POSIX_BUILTINS, but if
anyone would care to devise a test case, please do.

There's one potential strange edge case.  *Before* the patch below:

torch% foo=bar
torch% foo=fred \typeset foo=ding; echo . $foo .
. bar .
torch% foo=fred typeset foo=ding; echo . $foo . 
. ding .

*After* the patch:

torch% foo=bar
torch% foo=fred \typeset foo=ding; echo . $foo .
. bar .
torch% foo=fred typeset foo=ding; echo . $foo .
. bar .

I believe only the before+resword case is correct, that is, all four
should end up with "ding" assigned to $foo, and if that's true, it's
going to be pretty ugly to fix -- but it's possible that both after
cases are correct.


diff --git a/Src/exec.c b/Src/exec.c
index 9a7234e..d924148 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3543,7 +3543,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		     * if it's got "command" in front.
 		     * If it's a normal command --- save.
 		     */
-		    if (is_shfunc || (hn->flags & BINF_PSPECIAL))
+		    if (is_shfunc || (hn->flags & (BINF_PSPECIAL|BINF_ASSIGN)))
 			do_save = (orig_cflags & BINF_COMMAND);
 		    else
 			do_save = 1;
@@ -3552,7 +3552,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		     * Save if it's got "command" in front or it's
 		     * not a magic-equals assignment.
 		     */
-		    if ((cflags & BINF_COMMAND) || !assign)
+		    if ((cflags & (BINF_COMMAND|BINF_ASSIGN)) || !assign)
 			do_save = 1;
 		}
 		if (do_save && varspc)



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