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

Re: bug? - how to skip precmd



On Wed, 26 Sep 2007 21:29:52 +1200 (NZST)
Atom Smasher <atom@xxxxxxxxxxx> wrote:
> if i run a simple command followed by:
>  	&& return
>   or
>  	&& return n
> my precmd is ignored. that's just weird...

"return" at the top level causes the shell to leave and reenter the main
command loop, but without resetting the flag indicating the return is in
effect, which gets tested by the pre-command functions, which think they
need to return immediately.  (We treat "return" from the top level as
"exit" in a non-interactive shell to make functions work as scripts but we
deliberately don't do that in an interactive shell, so it's a rather
special case.)

Here's a minimal fix.

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.77
diff -u -r1.77 init.c
--- Src/init.c	26 Jul 2007 08:58:09 -0000	1.77
+++ Src/init.c	26 Sep 2007 09:53:23 -0000
@@ -1343,9 +1343,11 @@
 	 */
 	maybeshrinkjobtab();
 
-	do
+	do {
+	    /* Reset return from top level which gets us back here */
+	    retflag = 0;
 	    loop(1,0);
-	while (tok != ENDINPUT && (tok != LEXERR || isset(SHINSTDIN)));
+	} while (tok != ENDINPUT && (tok != LEXERR || isset(SHINSTDIN)));
 	if (tok == LEXERR) {
 	    /* Make sure a parse error exits with non-zero status */
 	    if (!lastval)


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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