Starting from 8.24 version of coreutils there is another way:
tee --output-error=warnp </dev/zero >(head -c100Mc10M | wc -c ) > >(head -c1 | wc -c ) >/dev/full | numfmt --to=iec
The output is
1
10M
The crucial points here are
- Use
--output-error=warnwhich will causeteeto issue only warning if fwrite returns EPIPE error instead of finishing.teewill run as long as there is at least one output file opened for writing.Use
-pwhich will causeteeto warn on errors writing to any output not a pipe. This means that EPIPE error onfwritewill not causeteeto exit andteewill run as long as there is at least one output file opened for writing. If you would like to get warning about EPIPE printed out to stderr use--output-error=warninstead-p. - Use
>/dev/fullto close tee's stdout. This is important for two reasons. If you use>/dev/nullfor exampleteewould run as long as stdin has data (forever in this case). At the same time it will allow output of>(process substitutions)to be send to stdout for the further processing.Use
> >(head -c1 | wc -c )to redirect tee's stdout to another>(process substitution). This is important for two reasons. You need to take care of stdout output produced bytee. If you use>/dev/nullfor exampleteewould run as long as stdin has data (forever in this case). At the same time it will allow output of>(process substitution)to be send to stdout for the further processing. Other possibilities but not so elegant are to closetee's stdout output by other means. Two possibilities are>/dev/fulland>&-. These will however issue a warnings (tee: standard output: No space left on device and tee: standard output: Bad file descriptor respectively)
Personally, I would love to have --no-stdout option implemented in tee rather than having to use >/dev/null trick. See this e-mail thread http://lists.gnu.org/archive/html/coreutils/2015-11/msg00070.html and post your arguents there if you would like to have --no-stdout option implemented in tee.