In
echo foo | tee >(rev) | (sleep 1; cat)
In bash
like in ksh
, but unlike zsh
, the stdout of rev
also is the pipe to (sleep 1; cat)
.
echo
, tee
, rev
and the (...)
subshell are started at the same time, but tee
writes foo\n
to stdout before the pipe to rev
, so in any case, rev
will write oof
to the pipe after tee
writes foo
, so oof
can only come last. Delaying cat
has no incidence.
If you wanted the output of rev
not to go through the pipe to (sleep 1; cat)
, you'd use zsh
or do:
{ echo foo 3>&- | tee >(rev >&3 3>&-) 3>&- | (sleep 1; cat) 3>&-; } 3>&1
Note that zsh
also has a builtin tee
in its multios
feature, so you can do:
echo foo > >(rev) > >(sleep 1; cat)
However in:
echo foo > >(rev) | (sleep 1; cat)
The output of rev
would go through cat
(confusingly considering it doesn't in the echo foo >(echo bar) | (sleep 1; cat)
case).
rev
goes throughcat
as well inbash
(contrary tozsh
)