Skip to content

Instantly share code, notes, and snippets.

@codingfoo
Last active December 8, 2015 16:31
Show Gist options
  • Save codingfoo/11182891 to your computer and use it in GitHub Desktop.
Save codingfoo/11182891 to your computer and use it in GitHub Desktop.
Bash script template
To perform a syntax check/dry run of your bash script run:
bash -n myscript.sh
To produce a trace of every command executed run:
bash -v myscripts.sh
To produce a trace of the expanded command use:
bash -x myscript.sh
-v -> set -o verbose
-x -> set -o xtrace
#!/usr/bin/env bash
set -o nounset
set -o errexit
set -o pipefail
exec >> /var/log/script.log
exec 2>&1
# cleanup on exit
function cleanup {
}
trap cleanup EXIT
# clear command line after ctrl-c
trap "{ echo; exit 1; }" INT
# Place code after traps so that they are registered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment