Last active
September 8, 2023 09:12
-
-
Save pistocop/85039a4cc8f6c846425792c75b66ad73 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
#!/usr/bin/env bash | |
# Template from: https://sharats.me/posts/shell-script-best-practices/ | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
if [[ "${TRACE-0}" == "1" ]]; then | |
set -o xtrace | |
fi | |
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then | |
# if [[ "$#" -ne 2 ]] || [[ "${1-}" =~ ^-*h(elp)?$ ]]; then # [OP2] make $1 and $2 mandatory | |
echo 'Usage: ./script.sh arg-one arg-two | |
This is an awesome bash script to make your life better. | |
Run with "$ TRACE=1 bash <scriptname>.sh" for debug. | |
' | |
exit | |
fi | |
cd "$(dirname "$0")" | |
ARG1=${1:-foo} # [OP2] $1 if mandatory | |
ARG2=${2:-foo} # [OP2] $2 if mandatory | |
main() { | |
echo do awesome stuff | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment