I still don't understand why setting the trap on a system that has
SIGPIPE vital doesn't work, so I'd be very greatful for any hints.
It's a lame restriction from POSIX based on historical practice (that
I _really_ wish we weren't stuck with):
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#trap
"Signals that were ignored on entry to a non-interactive shell cannot
be trapped or reset, although no error need be reported when
attempting to do so. An interactive shell may reset or catch signals
ignored on entry. Traps shall remain in place for a given shell until
explicitly changed with another trap command."
Maybe I don't get your point, but I think there might be a
missunderstanding: In my previous post I was referring to my example on
Linux, where SIGPIPE is not ignored by default:
for i in {0..9}; do echo $i; sleep 1; done | dd bs=1 count=10
ends as expected after 5 iterations, so SIGPIPE is not ignored in the
current shell;
trap '' pipe
for i in {0..9}; do echo $i; sleep 1; done | dd bs=1 count=10
reports a write error five times after the fifth iteration, as expected;
but installing another trap like
trap 'echo foo >&2' pipe
for i in {0..9}; do echo $i; sleep 1; done | dd bs=1 count=10
ends after 5 iterations (so SIGPIPE is not trapped, but handled again),
but does not write 'foo' to stderr (the terminal), and I don't
understand why.