Skip to content

Instantly share code, notes, and snippets.

@fortran01
Created January 28, 2020 18:18
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 fortran01/8c08e6a64d65fcaae4193ee6a385f7f5 to your computer and use it in GitHub Desktop.
Save fortran01/8c08e6a64d65fcaae4193ee6a385f7f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
logfile="my.log"
# Set up a named pipe for logging
npipe=/tmp/$$.tmp
mknod $npipe p
# Log all output to a log for error checking
tee <$npipe $logfile &
exec 1>&- # close stdout, produces 'write error: Bad file descriptor' if not re-opened below
exec 1>$npipe 2>&1 # 2>&1 redirect stderr to stdout
trap "rm -f $npipe" EXIT
# test
ls -al
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment