From: John Kelly on

Two copies of one input stream -- I think I did this before but I forgot
how. So I did it again. There's probably a better way, but this works:

The "cat >Stream " commands are just a sample; you can replace them with
whatever you want to do with each stream.



#!/bin/bash

exit_ () {
set +u
[[ $td == /tmp/[^/]* ]] && rm -rf $td || :
}
trap exit_ EXIT

td=`mktemp -d`

mkfifo "$td/f1"
exec 3<>"$td/f1"
exec 4> "$td/f1"
exec 3< "$td/f1"
(
exec <&3- 4>&-
cat >Stream1
) &

mkfifo "$td/f2"
exec 3<>"$td/f2"
exec 5> "$td/f2"
exec 3< "$td/f2"
(
exec <&3- 5>&-
cat >Stream2
) &

exec 3>&1 # Keep a copy of STDOUT so it can be restored later if needed

tee /dev/fd/4 >/dev/fd/5

exec 4>&- 5>&-

wait $!



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: John Kelly on
On Sat, 03 Jul 2010 05:57:54 +0000, John Kelly <jak(a)isp2dial.com> wrote:

>Two copies of one input stream -- I think I did this before but I forgot
>how. So I did it again. There's probably a better way

Seems there is -- process subsitution in bash:


#!/bin/bash

tee >(cat >Stream1) >(cat >Stream2) >/dev/null




>The "cat >Stream " commands are just a sample; you can replace them with
>whatever you want to do with each stream.
>
>
>
>#!/bin/bash
>
>exit_ () {
> set +u
> [[ $td == /tmp/[^/]* ]] && rm -rf $td || :
>}
>trap exit_ EXIT
>
>td=`mktemp -d`
>
>mkfifo "$td/f1"
>exec 3<>"$td/f1"
>exec 4> "$td/f1"
>exec 3< "$td/f1"
>(
> exec <&3- 4>&-
> cat >Stream1
>) &
>
>mkfifo "$td/f2"
>exec 3<>"$td/f2"
>exec 5> "$td/f2"
>exec 3< "$td/f2"
>(
> exec <&3- 5>&-
> cat >Stream2
>) &
>
>exec 3>&1 # Keep a copy of STDOUT so it can be restored later if needed
>
>tee /dev/fd/4 >/dev/fd/5
>
>exec 4>&- 5>&-
>
>wait $!

Same result, but the hard way. Oh well, it was good exercise with FIFOs
and redirection. After posting this, I noticed a small anomaly with the
"wait $!" and /dev/fd/4. It works OK as is, but two minor changes would
tighten it up.



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php