bug-bash
[Top][All Lists]
Advanced

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

Re: pipefail with SIGPIPE/EPIPE


From: Chet Ramey
Subject: Re: pipefail with SIGPIPE/EPIPE
Date: Sat, 25 Mar 2017 14:36:59 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 3/24/17 7:57 AM, Greg Wooledge wrote:
> On Thu, Mar 23, 2017 at 10:14:01PM -0700, Pádraig Brady wrote:
>> OK let's not derail this into a discussion specific to errexit.
>> Can we please improve things?
>> You say to not use errexit, and instead use `|| exit 1` where appropriate.
>> In that case can we fix this case?
>>
>>   set -o pipefail
>>   yes | head -n1 || exit 1
>>   echo this is skipped
> 
> What do you think is broken, here?
> 
> imadev:~$ yes | head -n1
> y
> imadev:~$ declare -p PIPESTATUS
> declare -a PIPESTATUS=([0]="141" [1]="0")
> 
> I don't see any problem in bash's behavior.  It's exiting because you
> asked it to exit if the pipe failed, and the pipe failed.  The pipe
> failed because yes(1) returned a nonzero exit code, and you turned on
> the pipefail option.

More precisely, `yes' died due to SIGPIPE, whose default action is to
terminate the process, so its exit status is 128+SIGPIPE.

> What exactly are you asking to change?

That's what he's asking to change.  He wants bash to mask the occurrence
of SIGPIPE, so that a command that dies due to SIGPIPE doesn't `fail'.
He is asking that SIGPIPE be made special, so that a process dying due to
it appears to exit with a status of 0.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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