I am trying to run the following script using getopts to parse the options but it does not seem to work:
#!/bin/bash
set -x
echo $@
while getopts "rf" opt
do
case "${opt}" in
r)
ropt=${OPTARG}
;;
f)
fopt=${OPTARG}
;;
esac
done
shift $((OPTIND -1))
echo $fopt $ropt
The output I get is:
$ ./myscript.sh -f opt2 -r opt1
+ echo -f opt2 -r opt1
-f opt2 -r opt1
+ getopts rf opt
+ case "${opt}" in
+ fopt=
+ getopts rf opt
+ shift 1
+ echo
+ set +x
Do you have any ideas on what am I doing wrong?