Skip to content

Instantly share code, notes, and snippets.

@mitchelhaan
Created March 2, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchelhaan/3df325acab381236596ffa33f32dc752 to your computer and use it in GitHub Desktop.
Save mitchelhaan/3df325acab381236596ffa33f32dc752 to your computer and use it in GitHub Desktop.
Redirect stderr and stdout to a file and the screen for an entire script
#!/bin/bash -u
logfile=output.log
# Combine stdout with stderr and pipe to a log file and the screen
exec > >(tee "$logfile") 2>&1
# Both of these messages should show up in the console and in the logfile
echo "Test stdout"
echo "Test stderr" >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment