Help with getopts command

Hello All,
I have shell script as below in a.ksh.

#! /usr/bin/ksh
while getopts a: b: ab:f: VAR
do
case $VAR in
a) A=${OPTARG}
echo $A;;
b) B=${OPTARG}
echo $B;;
ab) AB=${OPTARG}
echo $AB ;;
f) F=${OPTARG}
echo $F ;;
esac
done

When I execute sh a.ksh -a 1 -b 2 -ab 3 -f 4 as below and displays

1
2
b

Instead of as below

1
2
3
4

As I understand a,b's are repetitive that is the reason it is not working if there is a way to make it work please let me know.

What OS are you using? AFAIK, most don't support long options. ie -ab.

Agreed with purdym.
In case of

a.ksh -a 1 -b 2 -ab 3 -f 4

b is taken as argument for option a
if we try

a.ksh -a 1 -b 2 -ab3 -f 4

output will be

1
2
b3
4
 

I am sorry I would have put OS earlier: Linux 2.6.9-67.ELsmp.
Thank you for your quick response.

As a follow up, if someone knows how to make long options in KSH, I'd be interested in knowing how.

I want to thank you purdym and anurag.singh for reply.
As I said it is more like repetitive option issue. For example if do as below it is working fine.

#! /usr/bin/ksh
while getopts a: b: cd:f: VAR
do
  case $VAR in
    a) A=${OPTARG}
      echo $A;;
    b) B=${OPTARG}
      echo $B;;
    c) RESET_IF_REQUIRED=1 ;;
    d) DSSERVER=${OPTARG}
      echo "3" ;;
    f) F=${OPTARG}
      echo $F ;;
  esac
done
echo "Final"

Execute

$ sh a.ksh -a 1 -b 2 -cd 3 -f 4
1
2
3
4
Final

I hope there is way to do it but I am not that good with UNIX.

You just need the dash before every option...

sh a.ksh -a 1 -b 2 -c -d 3 -f 4

Also like this:

sh a.ksh -a 1 -b 2 -a 2 -b 3 -f 4

You can definitely repeat options.

Hi.

You could look on page unsorted resources at file

getopts_long.sh
    a getopts that supports long options � la GNU for POSIX shells 

The author is a well-known contributor on comp.unix.shell

Best wishes ... cheers, drl