Created
October 28, 2021 08:00
-
-
Save emolr/d77751b92b7fe9165efb97285a775d43 to your computer and use it in GitHub Desktop.
Script Description
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
#!/usr/bin/env bash | |
# Like this script? | |
# Generate boilerplate for similar ones at https://bashplate.wolfgang-werner.net. | |
set -o errexit # exit on error | |
set -o nounset # don't allow unset variables | |
# set -o xtrace # enable for debugging | |
usage() { | |
printf "Script Description\n" | |
printf "Usage: $(basename "$0") " | |
printf -- "[-h] " | |
printf -- "[-v] " | |
printf -- "-t=< test > " | |
printf "\n" | |
printf " -%s\t%s - %s%s\n" "h" "help" "Show this help message." "" | |
printf " -%s\t%s - %s%s\n" "v" "version" "Show version information." "" | |
printf " -%s\t%s - %s%s\n" "t" "test" "Test parameter for test" " (default: test content)" | |
} | |
version() { | |
printf "0.0.1\n" | |
} | |
# default values | |
opt_help="false" | |
opt_version="false" | |
opt_test="test content" | |
# declared functions | |
# option parsing | |
OPTSPEC=:hvt: | |
while getopts $OPTSPEC option; do | |
case "$option" in | |
h ) opt_help="true"; usage; exit 0 ;; | |
v ) opt_version="true"; version; exit 0 ;; | |
t ) opt_test=$OPTARG; ;; | |
\? ) echo "Unknown option: -$OPTARG" >&2; exit 1;; | |
: ) echo "Missing option argument for -$OPTARG" >&2; exit 1;; | |
* ) echo "Unimplemented option: -$OPTARG" >&2; exit 1;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
# required option validation | |
if [ -z "$opt_test" ] ; then | |
usage | |
exit 1 | |
fi | |
# convenience variables | |
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")" | |
__base="$(basename ${__file} .sh)" | |
__root="$(cd "$(dirname "${__dir}")" && pwd)" # update this to make it point your project's root | |
# this would be a good place to start writing your actual script. | |
echo "$__base was called with..." | |
echo -h=$opt_help | |
echo -v=$opt_version | |
echo -t=$opt_test | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment