Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: broken pipe message with setopt PRINT_EXIT_VALUE
- X-seq: zsh-workers 48944
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Samuel Bancal <Samuel.Bancal@xxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: broken pipe message with setopt PRINT_EXIT_VALUE
- Date: Fri, 28 May 2021 21:01:37 +0100
- Archived-at: <https://zsh.org/workers/48944>
- In-reply-to: <b34b34de-dc52-8d24-9b3a-c641bb9bbd79@epfl.ch>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Samuel Bancal <Samuel.Bancal@xxxxxxx>, zsh-workers@xxxxxxx
- References: <b34b34de-dc52-8d24-9b3a-c641bb9bbd79@epfl.ch>
2021-05-28 19:06:00 +0200, Samuel Bancal:
[...]
> < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c 32; echo;
> XKCxcd1QQ8otBre05qUDrvw2GFIdpYNr[1] 97774 broken pipe tr -dc
> _A-Z-a-z-0-9 < /dev/urandom |
> 97775 done head -c 32
[...]
Same in yes | head -n 1
In both cases, tr/yes are being killed (with a SIGPIPE) because
they're trying to write to a pipe that has no reader. If they
weren't killed they would run forever as /dev/urandom is of
infinite size and yes never terminates.
When a process is killed, it returns a non-zero (failure) exit
status to its parent.
Which is printed (or rather here the "broken pipe" message
corresponding to that death-by-SIGPIPE) because of
PRINT_EXIT_VALUE.
PRINT_EXIT_VALUE (-1)
Print the exit value of programs with non-zero exit status. This
is only available at the command line in interactive shells.
Even if you ignored SIGPIPE (which in general you don't want to):
~$ (trap '' PIPE; yes) | head -n1
y
yes: standard output: Broken pipe
zsh: exit 1 ( trap '' PIPE; yes; ) |
zsh: done head -n1
You still get a message as this time, yes exit with a failure
status because the write it tried to do on that pipe failed with
a "EPIPE" error.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author