Created
March 2, 2017 21:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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