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

Error status of "repeat" (was Re: [PATCH] typeset: set $? on incidental error)

On Jan 26, 10:50pm, Daniel Shahaf wrote:
} What would you expect "repeat 0+++ (exit 42)" to set $? to?

In fact what it does set $? to, is 0.

}        repeat WORD do LIST done
}               WORD is expanded and treated as an arithmetic expression, which
}               must evaluate to a number N.  LIST is then executed N times.

Hmm, this doesn't actually appear to happen.

torch% x=1+3
torch% repeat x print -n Z
torch% repeat $x print Z

So it's just peeling the first thing that looks like a number off the
WORD and repeating that many times, or zero times if WORD is not a number.

BUT!  Even if we change the code --

diff --git a/Src/loop.c b/Src/loop.c
index 4def9b6..61dad09 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -493,7 +493,7 @@ execrepeat(Estate state, UNUSED(int do_exec))
     tmp = ecgetstr(state, EC_DUPTOK, &htok);
     if (htok)
-    count = atoi(tmp);
+    count = mathevali(tmp);

-- that doesn't change the exit status!

torch% repeat 0+++ (exit 42)
zsh: bad math expression: lvalue required
torch% print $?

Next question: Do I commit that patch?

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