Last active
October 27, 2022 20:30
-
-
Save crizCraig/f42bc250754bed764ada5f95d101dbea to your computer and use it in GitHub Desktop.
bash boilerplate
This file contains 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 -e # Abort script at first error, when a command exits with non-zero status (except in until or while loops, if-tests, list constructs) | |
set -u # Attempt to use undefined variable outputs error message, and forces an exit | |
set -x # Similar to verbose mode (-v), but expands commands | |
set -o pipefail # Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value. | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# end boilerplate from: https://gist.github.com/crizCraig/f42bc250754bed764ada5f95d101dbea |
From https://sharats.me/posts/shell-script-best-practices/
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo 'Usage: ./script.sh arg-one arg-two
This is an awesome bash script to make your life better.
'
exit
fi
cd "$(dirname "$0")"
main() {
echo do awesome stuff
}
main "$@"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please consider