Skip to content

Instantly share code, notes, and snippets.

@takakabe
Created March 30, 2022 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takakabe/b79e9a8f282fdd761c1ee110409f5df4 to your computer and use it in GitHub Desktop.
Save takakabe/b79e9a8f282fdd761c1ee110409f5df4 to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
echo 'usage: ./opt_test.sh --alpha [ALPHA] --bravo [BRAVO] [--charlie [CHARLIE]]'
}
while [[ ${#} -gt 0 ]]; do
opt="${1}"
shift
value="${1}"
if [[ "${value}" =~ ^-{1,2}.* ]]; then
echo "Error: Argument is blank."
exit 1
fi
case "${opt}" in
"-a"|"--alpha" )
alpha="${1}"
shift
;;
"-b"|"--bravo" )
bravo="${1}"
shift
;;
"-c"|"--charlie" )
charlie="${1}"
shift
;;
* )
echo "ERROR: Invalid option: \""${opt}"\"" >&2
exit 1
;;
esac
done
if [[ -z "${alpha}" || -z "${bravo}" ]]; then
usage
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment