Created
November 21, 2022 08:44
-
-
Save Kyngo/c3fef00cb30e764f2b0f1d5aa5e42373 to your computer and use it in GitHub Desktop.
Proper Bash script template
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 | |
# Inspired on https://sharats.me/posts/shell-script-best-practices/ | |
set -o errexit # if something fails, the script will halt | |
set -o nounset # if an unset variable is being read, the script will halt | |
set -o pipefail # if a command in a pipe fails, the script will halt | |
# Do we want to debug this script? | |
if [[ "${TRACE-0}" == "1" ]]; then | |
set -o xtrace | |
fi | |
# Let's go to the script path | |
cd "$(dirname "$0")" | |
# Help function | |
help() { | |
# TODO: Add help message here | |
echo ' | |
Usage: '${0}' [--help] | |
--help: will show this message and exit the program | |
' | |
exit 0 | |
} | |
# Add your additional functions before "main", if any. | |
# Main function | |
main() { | |
# TODO: Add your logic here | |
echo "Hello, world!" | |
exit 0 | |
} | |
# Startup logic | |
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then | |
help "$@" | |
else | |
main "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment