I want to redirect stdout and stderr to a file while preserving the order of output but then also show stderr to screen. I see a lot of questions discuss it:
- https://unix.stackexchange.com/questions/9646/show-only-stderr-on-screen-but-write-both-stdout-and-stderr-to-file
- https://unix.stackexchange.com/questions/333198/bash-redirect-stderr-to-file-and-stdout-stderr-to-screen
- https://unix.stackexchange.com/questions/364166/redirect-bash-stdoutstderr-to-one-file-and-stderr-to-another-file
- Write STDOUT & STDERR to a logfile, also write STDERR to screen
But none of them seem to do what I want or preserve the order.
My test script:
#!/bin/bash
echo "1: good" >&1
echo "2: error" >&2
echo "3: error" >&2
echo "4: good" >&1
echo "5: error" >&2
echo "6: good" >&1
echo "7: error" >&2
echo "8: good" >&1
echo "9: error" >&2
What I have so far:
$ ./test.sh 2>&1 > output.log