Skip to content

Instantly share code, notes, and snippets.

@pistocop
Last active September 8, 2023 09:12
Show Gist options
  • Save pistocop/85039a4cc8f6c846425792c75b66ad73 to your computer and use it in GitHub Desktop.
Save pistocop/85039a4cc8f6c846425792c75b66ad73 to your computer and use it in GitHub Desktop.
bash script template
#!/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