67 lines
1.2 KiB
Bash
67 lines
1.2 KiB
Bash
|
#!/bin/bash --posix
|
||
|
|
||
|
|
||
|
usage() {
|
||
|
# Print out usage instructions for the local script
|
||
|
#
|
||
|
# Arguments:
|
||
|
# None
|
||
|
#
|
||
|
# Usage:
|
||
|
# usage
|
||
|
#
|
||
|
# POSIX Compliant:
|
||
|
# Yes
|
||
|
#
|
||
|
printf "Usage: %s %s\n" \
|
||
|
"$(basename ${0})" \
|
||
|
"-i \"this is some input\" -t \"this is some more example input\"
|
||
|
--input <string> | -i <string>
|
||
|
Example:
|
||
|
--input \"this is an example input\"
|
||
|
--test <string> | -t <string>
|
||
|
Example:
|
||
|
--test \"this is more example input\""
|
||
|
}
|
||
|
|
||
|
parse_args() {
|
||
|
# Parse input arguments
|
||
|
#
|
||
|
# Arguments:
|
||
|
# Consult the `usage` function
|
||
|
#
|
||
|
# Usage:
|
||
|
# parse_args "$@"
|
||
|
# - All arguments should be ingested by parse_args first for variable setting
|
||
|
#
|
||
|
# POSIX Compliant:
|
||
|
# Yes
|
||
|
#
|
||
|
|
||
|
while :; do
|
||
|
case ${1} in
|
||
|
-h | -\? | --help)
|
||
|
usage # Display a usage synopsis.
|
||
|
exit
|
||
|
;;
|
||
|
--) # End of all options.
|
||
|
break
|
||
|
;;
|
||
|
-i | --input)
|
||
|
echo "${2}"
|
||
|
;;
|
||
|
-t | --test)
|
||
|
echo "${2}"
|
||
|
;;
|
||
|
-?*)
|
||
|
printf 'Unknown option: %s\n' "$1" >&2
|
||
|
usage
|
||
|
;;
|
||
|
*) # Default case: No more options, so break out of the loop.
|
||
|
break ;;
|
||
|
esac
|
||
|
shift 2
|
||
|
done
|
||
|
}
|
||
|
|
||
|
parse_args "$@"
|