Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active Jul 14, 2022
Embed
What would you like to do?
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