* [bug] shift: shell exits with status 0 on bad math expression
@ 2018-06-20 8:45 ` Martijn Dekker
2018-06-20 9:12 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Martijn Dekker @ 2018-06-20 8:45 UTC (permalink / raw)
To: Zsh hackers list
When an argument is given to 'shift' that constitutes a bad math
expression, the (sub)shell prints an error and exits, but the exit
status is zero (= success) under most conditions.
$ zsh -c 'shift @/@'; echo $?
zsh:1: bad math expression: illegal character: @
0
$ zsh -c 'builtin shift @/@'; echo $?
zsh:1: bad math expression: illegal character: @
0
$ zsh -c 'emulate sh; shift @/@'; echo $?
zsh:1: bad math expression: illegal character: @
1
$ zsh -c 'emulate sh; command shift @/@'; echo $?
zsh:1: bad math expression: illegal character: @
0
The exit status should be non-zero in all cases.
The behaviour is the same from current git down to zsh 5.0.7, the
earliest version I tested.
- M.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [bug] shift: shell exits with status 0 on bad math expression
2018-06-20 8:45 ` [bug] shift: shell exits with status 0 on bad math expression Martijn Dekker
@ 2018-06-20 9:12 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2018-06-20 9:12 UTC (permalink / raw)
To: Zsh hackers list
On Wed, 20 Jun 2018 09:45:36 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> When an argument is given to 'shift' that constitutes a bad math
> expression, the (sub)shell prints an error and exits, but the exit
> status is zero (= success) under most conditions.
diff --git a/Src/builtin.c b/Src/builtin.c
index 1cba97d..93fa911 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5318,8 +5318,13 @@ bin_shift(char *name, char **argv, Options ops, UNUSED(int func))
/* optional argument can be either numeric or an array */
queue_signals();
- if (*argv && !getaparam(*argv))
+ if (*argv && !getaparam(*argv)) {
num = mathevali(*argv++);
+ if (errflag) {
+ unqueue_signals();
+ return 1;
+ }
+ }
if (num < 0) {
unqueue_signals();
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-20 9:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20180620090022epcas1p4700aca92f8b52c669c5ac10165a6ce80@epcas1p4.samsung.com>
2018-06-20 8:45 ` [bug] shift: shell exits with status 0 on bad math expression Martijn Dekker
2018-06-20 9:12 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).