Shell Script Best Practices

jagben
Oct 28, 2022

Basic template:

#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
if [[ -n "${TRACE-}" ]]; 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 "$@"

source and explanation

--

--

jagben
0 Followers

a list of things i want to remember