I have this script that I have cobbled together from bits of lore I've gleaned from googling:
#!/usr/bin/env bash
usage() {
declare -r script_name=$(basename "$0")
echo """
Usage:
"${script_name}" [option] <name>
Option:
-host <foo.com|bar.com|baz.com|...>
-accountId <001123456789|002123456789|...>
"""
}
main() {
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
OPTIONS=$(getopt -o '' -l help,host,accountId -- "$@")
eval set -- "$OPTIONS"
while true
do
case $1 in
-help) usage
exit 0
;;
-accountId) ACCOUNTID=$2; shift 2;;
-host) HOST=$2 shift 2;;
--) shift ; break ;;
esac
done
echo host: $HOST, accountId: $ACCOUNTID
}
main "$@"
Here's what it outputs:
$ . test.sh -help
host: , accountId:
$ . test.sh -host foo.com -accountId 001123456789
host: , accountId:
What have I done wrong?
--, as in--accountId.