You almost had it:
myprog | tee >(ap1) >(ap2) >(ap3) >/dev/null
Note that ap1
can be a function. If you want the function to have access to your script's argument, call it with "$@"
, i.e.,
ap1 () {
# here the script arguments are available as $1, $2, ...
}
# ditto for ap2, ap3
myprog | tee >(ap1 "$@") >(ap2 "$@") >(ap3 "$@") >/dev/null
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.
{ { { myprog | tee /dev/fd/3 /dev/fd/4 |
ap1 >&2
} 3>&1 |
ap2 >&2
} 4>&1 |
ap3 >&2
}
Gilles
2010-08-26 18:26:45