To output both stdout and stderr from a script to the console and to a log file, I’ve found a beautiful solution with tee:
exec &> >(tee log.file)
The problem is, that sometimes tee seems to be eating newlines. For example, I have a trap on exit that prints a newline and only then exits.
trap "echo && exit 55" EXIT HUP INT QUIT KILL
It makes the shell print the prompt from the new line instead of wherever user might have pressed
^C while the script was running. And it doesn’t work, when there’s such a call to exec.