Reading command options one by one

Hi,

Just some questions on the script below...?

Given: bash-2.03$ command -a option1 name1 name2

ParseOptions()
{
    local Len=${#@}
    local Ctr=2 #always start at 2
    local Name=()
    local Iter=0
    while [ $Ctr -lt $Len] ; do
        if [ $Ctr -eq "-a" ]            <- Is this correct? so I can get the $2 ("-a")
            Ctr=$(($Ctr + 1))
            local Option=$Ctr         <- Is this correct?
        else
            Name[$Iter]=$Ctr         <- Is this correct?
            Iter=$(($Iter + 1))
        fi
        Ctr=$(($Ctr + 1))
    done
}

Is there a better way to do this?
Note that the command may or may not have options, and the options can be interchanged (ex. bash-2.03$ command name3 -a option2)

also I need to check for this:

bash-2.03$ command name3 -a option2 name2

-> Should I make this an error?
kindly advise.

Thanks!

Refer to the bash documentation for information on how to use the getopts builtin.

Regards,
Alister

hmm ok..
but upon checking I think I cannot use it I don't have a '-<letter> option for the
names...and the names can be either before or after the '-a' option..