bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible getopts bug


From: Doug Jolley
Subject: Possible getopts bug
Date: Wed, 14 Nov 2001 17:15:17 -0800

Hi --

Running GNU bash, version 2.05.0(1)-release (i386-slackware-linux-gnu)
Copyright 2000 Free Software Foundation, Inc.  I'm concerned
that there is a bug in the way that getopts increments OPTIND
when options are combined following a single introductoyr-.
Consider the following which I believe to be correct operation:

$ cat bashbug1
#!/bin/bash

set -- -a -b arg1
echo -e "Initial Value of OPTIND: $OPTIND\n"
while getopts ab optname
do
  echo "Option: $optname        OPTIND: $OPTIND"
done
$ ./bashbug1
Initial Value of OPTIND: 1

Option: a       OPTIND: 2
Option: b       OPTIND: 3
$

As I say, I consider the above to be correct operation in that
OPTIND is incremented from its initial value of one once for
each of the two times that getopts is called.  Now, consider
the following where the two options are combined:

$ cat bashbug2
#!/bin/bash

set -- -ab arg1
echo -e "Initial Value of OPTIND: $OPTIND\n"
while getopts ab optname
do
  echo "Option: $optname        OPTIND: $OPTIND"
done
./bashbug2
Initial Value of OPTIND: 1

Option: a       OPTIND: 1
Option: b       OPTIND: 2
$

Notice in the above that, for purposes of incrementing OPTIND,
getopts seems to improperly treat the two options as a single
option.  Put differently, it would seem that the value placed
into OPTIND shouldn't depend on whether options are combined
following a single introductory - or expressed separately.  Am
I missing something?

Thanks.

     ... doug
_____________________________________________________________________
Doug Jolley     mailto://doug@footech.com      http://www.footech.com
         Don't bogart that file, my friend.  Net it over to me.
---------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]