I have a function test1
which produces output on both stdout
and stderr
:
test1() {
echo "out 1"
sleep 0.1
echo "error 1" 1>&2
sleep 0.1
echo "out 2"
sleep 0.1
echo "error 2" 1>&2
sleep 0.1
}
I then have two aliases which format stdin
and send it to stdout
:
alias o='sed -E "s/^/O /"'
alias e='sed -E "s/^/E /"'
How can I pipe the two streams from test1
through o
and e
and end up with formatted output on stdout
and stderr
? I'm using Bash on Alpine Linux, so GNU utilities are not an option.
My reasoning goes as follows, but I don't know how to execute it syntactically:
- Send
err
toout
andout
to3
. - Run
in
throughe
, send toerr
and3
toout
. - Run
in
througho
. - Profit?
test1 > >(o) 2> >(e >&2)
? – muru Jun 22 '20 at 07:16