This thread is very old, yet I wanted to post the solution in case someone reads this:
Lets say you want to run "some_command", log its outputs (including stderr) and also output stderr to the screen:
Code:
((some_command 2>&1 1>&3 | tee /dev/stderr) 3>&1) > logfile
This is not perfect because it does not return a correct exit code (it always returns 0 - the exit code of 'tee').
So we improve this a little bit:
Code:
((some_command 2>&1 1>&3 | tee /dev/stderr ; exit ${PIPESTATUS[0]}) 3>&1) > logfile
In case "some_command" is stored in a variable such as $cmd, I would suggest adding "eval" so that quotes are handled correctly:
Code:
((eval $cmd 2>&1 1>&3 | tee /dev/stderr ; exit ${PIPESTATUS[0]}) 3>&1) > logfile