So, I’m trying my hand at using bash’s built-in getopts to handle argument processing except I’m getting a strange result. Here’s my test script;
#!/bin/sh
HOST=
OWNER=
GROUP=
while getopts "h:o:g" OPTION;
do
case $OPTION in
h)
HOST=$OPTARG
;;
o)
OWNER=$OPTARG
;;
g)
GROUP=$OPTARG
;;
esac
done
echo "$HOST - $OWNER:$GROUP"
Yet, when I run the script using this;
./test.sh -h test.host.com -o skittles -g whatever
My last arg never gets pulled in or is getting dropped. My result from the echo is;
test.host.com - skittles:
^ where's my group value? O.o
Does anyone know what would be causing this?
Thanks.
It seems your expect
-gto have an argument, but in your options declaration, there is no “:” related to your-g.You should have this: