I just found out about process substitution using >()
and am super excited about it, however when I tried it, it doesn't always work. e.g.
This works:
cat /usr/share/dict/words |tee >(tail -1) > /dev/null
ZZZ
And this gives a broken pipe error:
cat /usr/share/dict/words |tee >(head -1) > /dev/null
1080
tee: /dev/fd/63: Broken pipe
Any idea why? Thanks!
Update: This is on RHEL 4 and RHEL 6.2
here's an explanation of why you get the error with head but not with tail:
head -1 only has to read one line of its input. then it will exit and the tee continues feeding its output into...
tail -1 on the other hand has to read the complete input in order to complete its job, so it will never terminate the pipe before tee is finished.
you can safely ignore the broken pipe message and many programs stopped reporting such errors. on my machine I don't see it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With