Re: How to get bash to shut up about SIGPIPE?
From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2016-06-15 22:41:56
Linus Torvalds [off-list ref] wrote:
But putting the traps _inside_ the loops seems to help. So something like the appended at least makes it somewhat useful
It's not the loop that's important, but the subshell where the signal is caught. Every time you enter a subshell all traps are reset. Since anything that comes (before or) after a pipe symbol goes into a subshell...
quoted hunk ↗ jump to hunk
Index: cg-log ===================================================================--- aa6233be6d1b8bf42797c409a7c23b50593afc99/cg-log (mode:100755 sha1:aa2abf370753117a350818dbc91991b14d30ec6b) +++ uncommitted/cg-log (mode:100755)@@ -47,10 +47,12 @@fi $revls | $revsort | while read time commit parents; do + trap "exit 1" SIGPIPE [ "$revfmt" = "git-rev-list" ] && commit="$time" echo $colheader""commit ${commit%:*} $coldefault; git-cat-file commit $commit | \ while read key rest; do + trap "exit 1" SIGPIPE case "$key" in "author"|"committer") if [ "$key" = "author" ]; then
You need it in both places because the signal may be received in either place, depending on whether it's the echo or something inside the loop that dies while writing output. Cheers, -- Visit Openswan at http://www.openswan.org/ Email: Herbert Xu ~{PmV>HI~} [off-list ref] Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt