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

Re: [bug] shift: shell exits with status 0 on bad math expression



On Wed, 20 Jun 2018 09:45:36 +0100
Martijn Dekker <martijn@xxxxxxxx> 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();



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