Code: Select all
exec 6>&1 # Link file descriptor #6 with stdout.
exec &> >(tee -a "$LOGFILE")
....
exec 1>&6
exec 6>&- # Restore stdout and close file descriptor #6.
exec &2> /dev/stderr
I'm looking for coding suggestions here. One thing that I think might be a good idea is if for some reason "6" ends up being a bad file descriptor I should do a fallback like:
Code: Select all
exec 1> /dev/stdin
or
exec 1> /dev/console
https://stackoverflow.com/questions/110 ... o-terminal0
If the program runs on a Linux environment, you can freopen ("/dev/stdout", "a", stdout).
But if you know that stdout was the terminal, freopen ("/dev/tty", "a", stdout) or the equivalent for other OSs—even Windows.
also what is the difference between:
Code: Select all
exec 1>&6
Code: Select all
exec &1>&6