Bash – SDERR and STDOUT File descriptors in a BASH script for logging

bash

I am trying to add rudimentary logging to a script which will be run daily by a cron job. Basically it goes along these lines:

LOGFILE=mylog.txt
exec 3<>$LOGFILE
2>&1
commands
...
exec 3>&-

Basically all I need to know is how to write the third line correctly so that STDERR and STDOUT both get written to FD 3, which is the log file. I've been fumbling around with it and sadly TLDP's explanation isn't the greatest – and most of the other tutorials on redirection and file descriptors don't go into this kind of depth. Any help would really be appreciated.

Best Answer

exec >&3 2>&3

And SF requires me to type some more characters, but that's all there is to it.