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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/