Reputation: 786
I have a script where I want to do the equivalent of this:
myscript | anotherprogram
but from within the script. I don't want to invoke
mysubtask | anotherprogram
each time I have to run my subtasks in my script, I just want the filter started and all my OUT & ERR routed to it (the script is not interactive).
So in the end what I want to do is
Upvotes: 2
Views: 650
Reputation: 122364
There are two simple ways I can see to achieve this. First, you could use a subshell with parentheses:
(
echo hello
echo world
) 2>&1 | anotherprogram
or you could use exec
to redirect the various file descriptors at the top of your script
exec > >( anotherprogram ) # send stdout to anotherprogram
exec 2>&1 # merge stderr into stdout
echo hello
echo world
Upvotes: 4