In a bash script I'd like to execute a command while piping the stderr to both a file and to the terminal. However, I want stderr to stay on the '2' file descriptor so that I can parse it from an external process that is calling this bash script.
All the solutions I've seen so far involve swapping stdout with stderr and then tee'ing to another file, for example:
find /var/log 3>&1 1>&2 2>&3 | foo.file
If I am to call this script from another one, the stderr will go to stdout and stdout will go to stderr, which is no good for me. I've tried to swap them again like so:
find /var/log 3>&1 1>&2 2>&3 | foo.file 4>&1 1>&2 2>&4
but this doesn't work.