In bash, this:
exec &> >(tee -a "$LOG_FILE")
Will redirect stderr & stdout to tee that allows the output to be displayed on the terminal while also logged (written to $LOG_FILE), but it uses process substitution, a feature not available in sh
If I run the script with sh:
sh script
I get:
syntax error near unexpected token `>'
In my attempt to have the same result in sh, I tried:
exec 2>&1 | tee -a "$LOG_FILE"
But I notice that nothing gets written to $LOG_FILE, instead I had to use:
exec > "$LOG_FILE" 2>&1
That writes the log to the file, but I don't see any output when running the script.
Any ideas?
From the accepted answer, the usage of:
mkfifo "$HOME/.pipe.$$"
helps/complements the suggested answer, since allows to have the code inline and not within a block