[Top][All Lists]

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

Re: pipefail with SIGPIPE/EPIPE

From: Pádraig Brady
Subject: Re: pipefail with SIGPIPE/EPIPE
Date: Fri, 24 Mar 2017 18:10:14 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 24/03/17 04:57, 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.
> What exactly are you asking to change?

I would like bash to treat SIGPIPE specially in this case,
as it's not an error, rather the standard "back pressure"
mechanism used in pipes.  The fact that SIGPIPE kills
by default is only a shortcut mechanism allowing processes
to exit automatically without changing their code.
The shell should not treat this as a real error though.

I.E. so I can write code like:

  set -o pipefail
  vv=$(yes | head) || exit 1
  echo finished

which will exit if yes(1) or head(1) segfault
or otherwise exit(1) etc., but proceed normally.


reply via email to

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