Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Re: Inconsistent behavior of ERR_EXIT with conditionals
- X-seq: zsh-workers 50897
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Re: Inconsistent behavior of ERR_EXIT with conditionals
- Date: Sun, 6 Nov 2022 21:35:05 -0800
- Archived-at: <https://zsh.org/workers/50897>
- In-reply-to: <CAH+w=7apH5_YnJtWT4x=mUOFhpHH1xMN9EkjjB0FJAi=8JQHdQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchsbWpFRsxS2CRzhdDix-B9osY_isv9nuBjbvt4nDTEWLA@mail.gmail.com> <CAH+w=7ZTSXUm6DLDk9k7z_V7YezKXJdcPi2uw1bTdmMjvTbkzg@mail.gmail.com> <CAH+w=7apH5_YnJtWT4x=mUOFhpHH1xMN9EkjjB0FJAi=8JQHdQ@mail.gmail.com>
On Sun, Nov 6, 2022 at 7:50 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> More questionable are the looping constructs. I can't come up with a
> way to have the loop end in an error state without the whole shell
> ERREXITing before reaching the end of the loop body.
Found the way (and it should have been obvious):
repeat 1; do false && true; done
The statement `false && true` doesn't itself cause an exit, but does
become $? of the loop.
Now the weird bit is that the attached patch DOES NOT cause a slew of
test failures in C03traps. E.g. if I run this test standalone:
Src/zsh -f =(<<<"(setopt err_exit
if true; then
false
fi
print OK
)")
I get no output and $? = 1. The exact same code in C03traps.ztst
prints OK, which it should not. The only difference I can see is that
ZTST_execchunk fiddles with localloops, but I've tried doing that too.
There is the question of why ignoring a false status at the end of a
complex command has so far been considered correct for ERR_EXIT,
according to C03. This is a disagreement with e.g. bash.
diff --git a/Src/exec.c b/Src/exec.c
index c8bcf4ee5..2422dae91 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -451,7 +451,7 @@ execcursh(Estate state, int do_exec)
cmdpop();
state->pc = end;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
diff --git a/Src/loop.c b/Src/loop.c
index db5b3e097..be5261369 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -208,7 +208,7 @@ execfor(Estate state, int do_exec)
loops--;
simple_pline = old_simple_pline;
state->pc = end;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
@@ -336,7 +336,7 @@ execselect(Estate state, UNUSED(int do_exec))
loops--;
simple_pline = old_simple_pline;
state->pc = end;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
@@ -478,7 +478,7 @@ execwhile(Estate state, UNUSED(int do_exec))
popheap();
loops--;
state->pc = end;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
@@ -532,7 +532,7 @@ execrepeat(Estate state, UNUSED(int do_exec))
loops--;
simple_pline = old_simple_pline;
state->pc = end;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
@@ -587,7 +587,7 @@ execif(Estate state, int do_exec)
lastval = 0;
}
state->pc = end;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
@@ -701,7 +701,7 @@ execcase(Estate state, int do_exec)
if (!anypatok)
lastval = 0;
- this_noerrexit = 1;
+ this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
return lastval;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author