system: freebsd 9.2
I want to use getopts to parse command line. Such as
./tesh.sh -o good a.c
can get good.out
./tesh.sh -o a.c
can get a.out
But in getopts there is no "option" variable. Does anyone know how to solve this problem? I found lots of webpages but no one can solve it.
here is my code
#!/bin/bash
while getopts "hs:o:" optname
do
case "$optname" in
"h")
echo "Option $optname is specified"
;;
"s")
echo "Option $optname has value $OPTARG"
;;
"o")
echo "$optname"
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
echo "OPTIND is now $OPTIND"
done
if i type ./test.sh -o a.c it will print echo "$optname"
and i want that if i type ./test.sh -o can also print echo "$optname"
now it will print wrong message
thx!