Last active
August 9, 2018 07:07
-
-
Save dlnilsson/47f19609424b54663983d14f461f9991 to your computer and use it in GitHub Desktop.
#bash #boilerplate
This file contains hidden or 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 | |
# https://explainshell.com/explain?cmd=set+-euxo%20pipefail | |
set -eou pipefail | |
yell() { echo "$0: $*" >&2; } | |
die() { yell "$*"; exit 111; } | |
try() { echo "$ $@" 1>&2; "$@" || die "cannot $*"; } | |
# log to syslog and echo output | |
info() { | |
echo -e "\n$1" | |
logger -t ProgramName "$1" | |
} | |
main() { | |
# do stuff here | |
info "ok" | |
} | |
function_one() { | |
echo "hello ${1:-}" | |
# usage: ./script.sh function_one world | |
# return hello world! | |
} | |
function_two() { | |
echo "hello ${1:-}" | |
# usage: ./script.sh function_one world | |
# return hello world! | |
} | |
display_help() { | |
echo "Usage: $0 [arguments...]" | |
echo | |
echo " -h | --help Display this help info" | |
echo " function_one Parameter one function_one" | |
echo " function_two Parameter one function_two" | |
echo | |
exit 1 | |
} | |
case "${1:-""}" in | |
# usage: ./script.sh function_one args | |
function_one) | |
function_one ${2:-} | |
exit 0 | |
;; | |
# usage: ./script.sh function_one args | |
function_two) | |
function_two ${2:-} | |
exit 0 | |
;; | |
-h | --help) | |
display_help | |
;; | |
#usage: ./script.sh arg1 arg2 arg3 | |
*) | |
main $@ | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment