mail me! sindicaci;ón

Redirect *all* BASH errors

A friend helped me out with a shell script I’m currently creating. I was trying to avoid having to append 2> to the end of every command within the script, and lo-and-behold my friend knew a way: use the exec command.

If you run exec with no arguments, all redirects apply to the current shell, so placing:

#!/bin/bash
exec 2> $errorlog
errorlog=”/var/log/custom.log”

Worked a treat!

Leave a Comment