I'm trying to use getopts for a bash script. This script can have flags and all of those flags are mandatory and need to contain a value. When one of the mandatory flags that supposed to contain a value is empty getopts use the next-in-line flag as his content. How do I prevent this?
This is my example:
#!/bin/bash
while getopts "A:B:" OPTION
do
case $OPTION in
A)
GILIA="$GILIA $OPTARG"
echo GILIA $GILIA
;;
B)
GILIB="$GILIB $OPTARG"
echo GILIB $GILIB
;;
esac
done
When using both flags with value:
./test_opt2 -A aaa -B bbb
GILIA aaa
GILIB bbb
When using "-A" flag empty:
./test_opt2 -A -B bbb
GILIA -B
I know that this is normal/typical behavior of getopts and I'm sure there is a way to go around this...
Any ideas?