When using tee with process substitution, if the process exits early it
will cause tee to get a SIGPIPE after trying to write to the closed named
pipe (per man 2 write). This causes tee to exit without finishing writing
to any additional files or processes, which seems to be a violation of the
POSIX standard at
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html
specifically the Consequences of Errors section which states
"If a write to any successfully opened file operand fails, writes to other
successfully opened file operands and standard output shall continue, but
the exit status shall be non-zero. Otherwise, the default actions
specified in Utility Description Defaults apply."
To recreate the problem I ran the following under bash:
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
And I see output like the following:
1
Head done
2
and then it exits with echo "${PIPESTATUS[@]}" showing
141 141
and t.txt from the second process substitution only having "1" in it
This was found from a Stack Overflow question at
http://stackoverflow.com/questions/34340706/incorrect-results-with-bash-process-substitution-and-tail
I have verified this behavior with tee (GNU coreutils) 8.5 and tee (GNU
coreutils) 8.13