GNU bug report logs -
#22195
deviation from POSIX in tee
Previous Next
Reported by: Eric Renouf <erenouf <at> skaion.com>
Date: Thu, 17 Dec 2015 20:35:01 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #14 received at 22195 <at> debbugs.gnu.org (full text, mbox):
tag 22195 notabug
close 22195
stop
On 18/12/15 03:22, Paul Eggert wrote:
> Eric Renouf wrote:
>> If a write to any successfully opened file operand fails
>
> But the write didn't fail here. Instead, a signal was sent to 'tee'. If you
> don't want the signal, trap it. E.g.:
>
> trap '' PIPE
> for i in {1..300}; do
> echo "$i"
> echo "$i" >&2
> sleep 1
> done | tee >(head -1 > h.txt; echo "Head done") \
> >(tail -1 > t.txt) >/dev/null
>
> will give the behavior you want.
>
> So there is no deviation from POSIX here.
Generally you don't want to ignore SIGPIPE.
http://pixelbeat/programming/sigpipe_handling.html
as then you have to deal with EPIPE from write():
$ trap '' PIPE
$ seq 100000 | tee >(head -n1) > >(sed -n '/10000/{p;q}')
1
10000
seq: write error
As Bernhard said, the new -p option is a solution to this:
$ seq 100000 | tee >(head -n1) > >(tail -n1)
1
14139
$ seq 100000 | tee -p >(head -n1) > >(tail -n1)
1
100000
Note that's an option, rather than the default behavior
as POSIX states to handle SIGPIPE in the default manner,
and more importantly to support existing cases like the
following (yes we don't support both modes of operation):
$ yes | tee log | timeout process
Since this is somewhat of a subjective default,
and this issue pops up so frequently, I've just added it to:
http://www.pixelbeat.org/docs/coreutils-gotchas.html#tee
cheers,
Pádraig
This bug report was last modified 6 years and 263 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.