zsh-workers
 help / color / mirror / code / Atom feed
* Failed pipeline doesn't err_exit/return if complex command last
@ 2023-07-05 23:18 Johan Grande
  2023-07-05 23:45 ` Johan Grande
  2023-07-06  9:44 ` Peter Stephenson
  0 siblings, 2 replies; 10+ messages in thread
From: Johan Grande @ 2023-07-05 23:18 UTC (permalink / raw)
  To: zsh-workers

Hi all,

I noticed a strange behavior when using a complex command in a pipeline.

With `set -eo pipefail`, a failing pipeline that ends in a complex
command will have non-zero status but not exit the script (or a function
with err_return):

     false | if true; then true; fi
     echo $?

=> prints "1", exits with 0

However, this only occurs if the `if` command is last. If we add a `|
true` at the end:

     false | if true; then true; fi | true
     echo $?

=> no output, exits with 1

Same with a while loop (I only checked these 2 complex commands):

     false | while read line; do true; done
     echo $?

=> prints "1", exits with 0

     false | while read line; do true; done | true
     echo $?

=> no output, exits with 1

It seems inconsistent to me that a complex command be treated just like 
a simple command in the middle of a pipeline but not at the end, making 
a "list" that has non-zero status but doesn't return/exit despite the 
options.

As a sanity check, I ran the examples with bash and the result is what I 
would expect in all 4 cases: no output, exit with 1.

I'm using zsh 5.8.1 (x86_64-ubuntu-linux-gnu).

-- 
Johan Grande


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-07-20  8:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-05 23:18 Failed pipeline doesn't err_exit/return if complex command last Johan Grande
2023-07-05 23:45 ` Johan Grande
2023-07-06  9:44 ` Peter Stephenson
2023-07-08  4:31   ` Bart Schaefer
     [not found]   ` <cf275400-d63a-d991-3aa5-1543d20a2f42@crans.org>
2023-07-16 14:36     ` Peter Stephenson
2023-07-17 19:25       ` Johan Grande
2023-07-17 23:34   ` Bart Schaefer
2023-07-18  1:51     ` Bart Schaefer
2023-07-18 13:57       ` Peter Stephenson
2023-07-20  8:47         ` 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).