Skip to content

Instantly share code, notes, and snippets.

@danijeel danijeel/index.sh
Last active Aug 9, 2018

Embed
What would you like to do?
#bash #boilerplate
#!/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
You can’t perform that action at this time.