problem with getopts

Hi, I am a new member to unix.com.

Actually I am facing a problem with getopts. In my script i have used getopts to parse the parameters. when i use the script as shown below its working fine:

find_status -p all ### where find_status is a script name.

But even if I pass more than one value with option "-p", the second value is not considered (its desired) and the script works.

find_status -p all abc ###'all' and 'abc' are argument values.

My problem is that how can i show an error if i pass more than one value to a parameter.

Please help me out.

please post in the right forum. thread moved!

You can check the number of arguments passed by $# e.g
if [ $# -ne 3 ]
then
echo error
exit 1
fi

The following might help you

#!/usr/bin/ksh93

CMD=$(basename $0)
USAGE="Usage: $CMD [-p argument]"

while getopts p: opt
do
    case "$opt" in
       'p') echo "-p $OPTARG specified"
            ;;
       '?') echo $USAGE
            exit 2
            ;;
    esac
done

shift $(($OPTIND - 1))
print "Remaining arguments are: $*"
exit 0