help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: weird interaction between builtin cat and trap


From: Jesse Hathaway
Subject: Re: weird interaction between builtin cat and trap
Date: Thu, 14 Apr 2022 11:11:19 -0500

On Thu, Apr 14, 2022 at 10:30 AM Chet Ramey <chet.ramey@case.edu> wrote:
> More or less. The trap has something to do with it, too.
>
> The builtin cat catches and reports write errors before it checks for fatal
> signals, including SIGPIPE. The coreutils cat just dies due to SIGPIPE
> (exit status 141).
>
> The trap EXIT causes bash to install a signal handler for the fatal
> signals, including SIGPIPE. (All it does is clean up, run the exit trap,
> and resend the signal to itself. And in this case the child running
> cat doesn't run the exit trap, so it's just a passthrough.)
>
> The coreutils cat doesn't do that. It may or may not check for write
> errors, but it certainly doesn't catch SIGPIPE. It terminates before it
> even has a chance to check for write errors.

Thanks for the clarification Chet, much appreciated.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]