[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#22195: deviation from POSIX in tee
From: |
Pádraig Brady |
Subject: |
bug#22195: deviation from POSIX in tee |
Date: |
Fri, 18 Dec 2015 11:13:10 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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