I have a bash file that I need to redirect all output to one file, debug log as well as to the terminal. I need to redirect both stdout and stderr to the debug and log it for all commands in the script.
I do not want to add 2>&1 | tee -a $DEBUG
for every single command in the file. I could live with | tee -a $DEBUG
.
I remember there was a way to do it with something like exec 2>&1
.
Currently I'm using something like the following:
#!/bin/bash
DEBUGLOG=/tmp/debug
exec 2>&1
somecommand | tee -a $DEBUGLOG
somecommand2 | tee -a $DEBUGLOG
somecommand3 | tee -a $DEBUGLOG
but it does not work. Does anyone have a solution/can explain the cause?