Last active
December 8, 2015 16:31
-
-
Save codingfoo/11182891 to your computer and use it in GitHub Desktop.
Bash script template
This file contains hidden or 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
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 |
This file contains hidden or 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
#!/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