Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active July 14, 2022 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotysan/ab998aad575f0636e339dd564049446b to your computer and use it in GitHub Desktop.
Save dotysan/ab998aad575f0636e339dd564049446b to your computer and use it in GitHub Desktop.
A template for seeding new Bash scripts.
#! /usr/bin/env bash
#
# A template for seeding new Bash scripts.
#
if [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]
then
echo "ERROR: Only tested on Bourne-Again SHell v4/v5."
exit 1
fi >&2
set -e
shopt -s nullglob
printf -v now '%(%FT%T%z)T'
main() {
foo "$@"
}
########################################################################
foo() {
echo "$now: $@"
}
########################################################################
# poor man's __main__
return 2>/dev/null ||:
if [ "$(type -t "$1")" = "function" ]
then
func="$1"
shift 1
$func "$@"
else
set -x # debugging
main "$@"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment