I'm trying to build a script in bash and building a getopts loop. I have two options(x and h) that don't have any arguments and the other two have it. But my while loop fails by taking only one option and doesn't take any other arguments, how can I make this work? m, p and s can have arguments whereas x and h will not have arguments
while getopts ":m:p:s:x:h:" option; do
case "${option}" in
m)
HOME_DIR=${OPTARG}
echo "The home dir is $HOME_DIR"
;;
p) URL=${OPTARG}
echo "The url is $URL"
;;
s) ID=${OPTARG}
echo "The server id is $ID"
;;
x) SKIP_SERVICE=${OPTARG}
echo "The skip service is $SKIP_SERVICE"
;;
h)
echo "Usage: $0 [options]"
echo " "
echo "options:"
echo "-h, show help"
echo "-m, set home directory - defaults to HOME"
echo "-p, enter URL"
echo " "
exit 0
;;
esac
done