I'm relatively new to this field, and I'm running my shell script named "statsrandomrun.sh" with following code snippets:
#!/bin/bash
while getopts "m:s:xh" opt; do
case $opt in
m)
MU=$OPTARG; mflag=true; ;;
s)
SIGMA=$OPTARG; sflag=true; ;;
h)
usage; exit;;
x)
xflag=true ;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "HaHa! Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
but it seems though whenever I pass this command
/.statsrandomrun.sh -m
I never see
echo "HaHa! Option -$OPTARG requires an argument." >&2
working, which I implemented in the above snippet. My bash just shows me some other message:
option requires an argument -- m
which I did not obviously put in my code. Also there follows another line
Invalid option: -
I expect this to take place, because the output from help getopts
contains the following:
If a required argument is not found, getopts places a ':' into NAME and sets OPTARG to the option character found.
What is happening? Any ideas? I'd appreciate any help in advance :)