Redirecting within a bash script

posted on 09:44 AM on Wednesday 03 July 2013

I use bash scripts to tie together different programs to get the results that I need and it is nice to be able to redirect all the stdout and stderr of all the programs to a single output file. In a bash script, you can add the following lines to the top of the script and that will redirect everything to the specified file.

exec > log.out
exec 2>&1

See the following links from which I got the information from:

http://www.tldp.org/LDP/abs/html/x17891.html

http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself

bernett.net