Skip to content

Instantly share code, notes, and snippets.

@djeikyb
Last active July 6, 2021 19:17
Show Gist options
  • Save djeikyb/106327707a80a1b7aff0510a0ef519b1 to your computer and use it in GitHub Desktop.
Save djeikyb/106327707a80a1b7aff0510a0ef519b1 to your computer and use it in GitHub Desktop.
common shell functions, a skeleton for new scripts
SELF=${0##*/}
die() {
log "$@"
exit 1
}
log() {
printf "$SELF: %s\n" "$@" >&2
}
usage() {
cat <<EOF
usage: $self [--help]
Examples:
$SELF --help
EOF
}
requireCommand() {
command -v $1 >/dev/null 2>&1 || die "'$1' is required, but not found"
}
while [ $# -gt 0 ]; do
case "$1" in
"")
usage
die "unrecognized argument: $1"
exit 1
;;
--help|help|-help|-h)
usage
exit 0
;;
somearg|-a)
shift
;;
*)
die "unrecognized argument: $1"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment