Skip to content

Instantly share code, notes, and snippets.

@grampelberg
Created February 5, 2021 18:23
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 grampelberg/baa1292c8ddd4b5e9f06f80dce198261 to your computer and use it in GitHub Desktop.
Save grampelberg/baa1292c8ddd4b5e9f06f80dce198261 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: demo
USAGE
}; function --help { -h ;} # A nice way to handle -h and --help
export LC_ALL=en_US.UTF-8 # A locale that works consistently
function output_shutdown {
printf "shutdown!\n"
}
function main {
printf "oh hai\n"
trap 'output_shutdown' TERM
sleep infinity
}
function msg { out "$*" >&2 ;}
function err { local x=$? ; msg "$*" ; return $(( $x == 0 ? 1 : $x )) ;}
function out { printf '%s\n' "$*" ;}
if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | fgrep -qx -- "${1:-}"
then "$@"
else main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment