bug-bash
[Top][All Lists]
Advanced

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

Re: builtins/getopt.c is broken. last working one was 2.05a


From: Chet Ramey
Subject: Re: builtins/getopt.c is broken. last working one was 2.05a
Date: Mon, 07 Apr 2003 09:28:08 -0400

> Machine Type: i686-pc-linux-gnu
> 
> Bash Version: 2.05b
> Patch Level: 0
> Release Status: release
> 
> Description:
> 
>       $OPTIND gets incremented on unmatched option.

I believe that this is the correct behavior, according to POSIX.2.  getopts
returns the option, even though it's not one of the recognized ones, because
it's of the correct form.

POSIX.2 says:

Each time it is invoked, the getopts utility shall place the value of
the next option in the shell variable specified by the name operand
and the index of the next argument to be processed in the shell
variable OPTIND.

Since getopts returns the unrecognized option (after a fashion; it sets
its `name' argument to `?'), and doesn't consider it an error, it should
increment OPTIND.

ksh93 behaves the same way, but the BSD sh does not.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )

Chet Ramey, ITS, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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