On 20/11/15 23:58, Jirka Hladky wrote: >> On Sat, Nov 21, 2015 at 12:01 AM, Bob Proulx <b...@proulx.com >> <mailto:b...@proulx.com>> wrote: >> >> Bernhard Voelker wrote: >> > I'm not convinced that a new --no-stdout option is warranted: >> > why not simply redirect stdout to the last fifo? >> > >> > cat /dev/zero | head -c500M \ >> > | (/dev/shm/AAA/coreutils-8.24/src/tee -p \ >> > $d/fifo1 $d/fifo2 $d/fifo3 > $d/fifo4 ) 2>&1 \ >> > | > tee $d/run.log & >> >> Of course! It was so obvious that we missed seeing it! Simply do a >> normal redirect of stdout to the process. Thanks Bernhard for >> pointing this out. >> >> This is also true of the >(process substitutions) too. >> >> echo foo | tee >(sleep 2 && cat) > >(sleep 5 && cat) >> >> This really argues against any need for --no-stdout. Because if one >> wants --no-stdout it means one has forgotten about a normal >> redirection. > > Yes, *this is* the solution I was looking for! > > tee -p </dev/zero >(head -c1 | wc -c ) > >(head -c10M | wc -c) > > Thanks to everybody to take part in the discussion and finally coming up with > the solution. > > Could we please add this example to tee's manual page into the EXAMPLE > section? If there is anything I can do to make it happen please let me know.
Yes it works well. I've added the construct to the existing tee examples in the attached. thanks, Pádraig.
From 15e9168976444fbe67a6fcf95035352bd0dcbbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> Date: Fri, 20 Nov 2015 11:54:00 +0000 Subject: [PATCH] doc: give a tee example for combining process substitution outputs This can be useful if you want to further process data from process substitutions. For example: datagen | tee >(md5sum --tag) > >(sha256sum --tag) | sort * doc/coreutils.texi (tee invocation): Mention that -p is useful with pipes that may not consume all data. Add an example, similar to the one above. * THANKS.in: Add Jirka Hladky. --- THANKS.in | 1 + doc/coreutils.texi | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/THANKS.in b/THANKS.in index 51c77ef..5c49006 100644 --- a/THANKS.in +++ b/THANKS.in @@ -299,6 +299,7 @@ Jesse Thilo j...@eecs.lehigh.edu Jie Xu x...@iag.net Jim Blandy j...@cyclic.com Jim Dennis j...@starshine.org +Jirka Hladky jhla...@redhat.com Joakim Rosqvist dvl...@cs.umu.se Jochen Hein joc...@jochen.org Joe Orton j...@manyfish.co.uk diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 8034807..a73a635 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -13019,6 +13019,11 @@ so it works with @command{zsh}, @command{bash}, and @command{ksh}, but not with @command{/bin/sh}. So if you write code like this in a shell script, be sure to start the script with @samp{#!/bin/bash}. +Note also that if any of the process substitutions (or piped stdout) +might exit early without consuming all the data, the @option{-p} option +is needed to allow @command{tee} to continue to process the input +to any remaining outputs. + Since the above example writes to one file and one process, a more conventional and portable use of @command{tee} is even better: @@ -13087,6 +13092,17 @@ tar chof - "$tardir" \ | bzip2 -9 -c > your-pkg-M.N.tar.bz2 @end example +If you want to further process the output from process substitutions, +and those processes write atomically (i.e. write less than the system's +PIPE_BUF size at a time), that's possible with a construct like: + +@example +tardir=your-pkg-M.N +tar chof - "$tardir" \ + | tee >(md5sum --tag) > >(sha256sum --tag) \ + | sort | gpg --clearsign > your-pkg-M.N.tar.sig +@end example + @exitstatus -- 2.5.0