Skip to content

Instantly share code, notes, and snippets.

@dathanb
Created October 28, 2021 03:40
Show Gist options
  • Save dathanb/fccc74fc15834129e9ae4f841826c88a to your computer and use it in GitHub Desktop.
Save dathanb/fccc74fc15834129e9ae4f841826c88a to your computer and use it in GitHub Desktop.
Redirect stdout and stderr from within a script
logFile=~/log
# close stdout and stderr and redirect them to the log file
rm -f "${logFile}"
exec 1<&-
exec 2<&-
exec 1<>"${logFile}"
exec 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment