I want to take stdout of a process and analyze it with three different programs. I have been able to use named pipes, but can I use fd’s instead.
Here’s what works so far:
exec 3< <(myprog)
tee p1 p2 >/dev/null <&3
cat p1|ap1 &
cat p2|ap2 &
p1 and p2 were created with mkfifo. ap1 and ap2 are analysis programs. I don’t know if I’m saying this right, but is there a way to tee into two new fd’s instead? Something like this:
exec 3< <(myprog)
tee >&4 >&5 <&3
cat <&4|ap1 &
cat <&5|ap2 &
You almost had it:
Note that
ap1can be a function. If you want the function to have access to your script’s argument, call it with"$@", i.e.,If your shell doesn’t support
>()(bash, ksh and zsh do, but it’s not POSIX), but your OS nonetheless supports/dev/fd(most unices do, including Solaris, Linux, *BSD, OSX and Cygwin), you can use explicit fd shuffling.