Skip to content

Instantly share code, notes, and snippets.

@takakabe
Created March 30, 2022 03:04
Embed
What would you like to do?
#!/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