Wednesday 3 October 2012

Redirect bash output to file and screen

So you have made a nice new script in bash. Fancy you! Alas it has to log to a file and to screen. That might sounds simple, and it is, check this out:

exec > >(tee ${LOGFILE}) 2>&1

WTH? Well just redirect all output (error and out) to a subprocess which tee's it (write to screen and to log).

No comments: