Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broken pipe in tee with process substituion

Tags:

bash

shell

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

like image 247
naumcho Avatar asked Nov 13 '22 08:11

naumcho


1 Answers

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.

like image 103
user829755 Avatar answered Nov 15 '22 06:11

user829755