Is there possibility to parse obligatory argument containing colon using getopt in bash?
Let's say I've prepared code like below:
while getopts "qt:i:" arg; do
case "$arg" in
:)
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
shift 1
;;
-q)
QUIET=1
shift 1
;;
-t)
TIMEOUT="$2"
if [ "$TIMEOUT" = "" ]; then break; fi
shift 2
;;
-i)
INTERVAL="$2"
if [ "$INTERVAL" = "" ]; then break; fi
shift 2
;;
-h)
usage 0
;;
*)
echoerr "Unknown argument: $1"
usage 1
;;
esac
done
Full code can be found here: https://pastebin.com/1eFsG8Qn
How i call the script:
wait-for database:3306 -t 60 -i 10
Problem is that this logic can't parse HOST_URL:PORT. Any tips how to parse it?