Created
February 5, 2021 18:23
-
-
Save grampelberg/baa1292c8ddd4b5e9f06f80dce198261 to your computer and use it in GitHub Desktop.
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
#!/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