From: Herbert Xu Date: Wed, 04 May 2005 08:26:25 GMT Subject: Re: How to get bash to shut up about SIGPIPE? Message-ID: In-Reply-To: Linus Torvalds 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... > 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~} Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt