Last active
July 14, 2022 14:40
-
-
Save dotysan/ab998aad575f0636e339dd564049446b to your computer and use it in GitHub Desktop.
A template for seeding new Bash scripts.
This file contains 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 | |
# | |
# 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