Skip to content

Instantly share code, notes, and snippets.

@jimjh
Last active August 29, 2015 14:26
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 jimjh/6904faaf7d99ea5662e9 to your computer and use it in GitHub Desktop.
Save jimjh/6904faaf7d99ea5662e9 to your computer and use it in GitHub Desktop.
script template
#!/usr/bin/env bash
# Usage:
# Without trace, just run `./do-stuff.sh`
# With trace, use `BASH_XTRACEFD=3 ./do-stuff 3> trace.txt`
# Requires bash 4.+
set -o pipefail
set -o nounset
set -o errexit
if [[ ${BASH_XTRACEFD:+x} ]]; then
set -o xtrace
fi
if false; then
cat /tmp/w00t > /dev/null
else
cat /tmp/w11t > /dev/null
fi
@jimjh
Copy link
Author

jimjh commented Aug 5, 2015

If BASH_XTRACEFD is set, turns on xtrace and outputs trace to the given file descriptor. Otherwise, does not use xtrace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment