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

Re: [bug] errexit and cmdsubst after "else"



On Sat, 2020-02-01 at 17:56 +0000, Stephane Chazelas wrote:
> From
> https://unix.stackexchange.com/questions/565158/command-substitution-does-not-respect-err-exit-sometimes
> 
> $ zsh -ec 'if false; then;else a=$(false); echo $?; fi'
> 1
> 
> expected no output because of errexit.

The following passes all tests; I hope we've been diligent in adding
test cases for previous failures as bug ping pong is a fairly silly
game...

Obviously, please do run any other tests you feel may be relevant (and I
will add them if we don't have them).

pws


diff --git a/Src/loop.c b/Src/loop.c
index 538afb8dc..01abc6cc9 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -570,7 +570,7 @@ execif(Estate state, int do_exec)
 
     if (run) {
 	/* we need to ignore lastval until we reach execcmd() */
-	if (olderrexit)
+	if (olderrexit || run == 2)
 	    noerrexit = olderrexit;
 	else if (lastval)
 	    noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC;
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index e661aabd5..6f84e5db2 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -500,6 +500,15 @@
 >Succeed 2
 >Succeed 3
 
+  (set -e
+   if false; then
+   else
+       a=$(false)
+       print This should not appear
+   fi
+  )
+1:ERREXIT is triggered in an else block after a cmd subst returning false
+
   fn() {
     emulate -L zsh
     setopt errreturn



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