Re: How to get bash to shut up about SIGPIPE?
- From
- Herbert Xu <herbert@gondor.apana.org.au>
- Date
- May 4, 2005, 08:26 UTC
- Message-ID
- <E1DTFD7-00063T-00@gondolin.me.apana.org.au>
- In-Reply-To
- <Pine.LNX.4.58.0505031947530.26698@ppc970.osdl.org>
Linus Torvalds <torvalds@osdl.org> 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...
Show 17 quoted lines
> 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" ]; thenYou 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~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt