Skip to content

Using + getopts flags seems to enable a +- option #1050

Open

Description

@stephane-chazelas
$ ksh93 -c 'while getopts "[-+][o]" opt; do typeset -p opt OPTARG OPTIND; done' myscript +---o
opt=+-
OPTARG=1
typeset -i OPTIND=1
opt=+-
OPTARG=1
typeset -i OPTIND=1
opt=+-
OPTARG=1
typeset -i OPTIND=1
opt=+o
OPTARG=1
typeset -i OPTIND=2

That [-+] at the start is meant to enable the extended interface, with the + flag being for:

+
Arguments beginning with + are considered options.

So that getopts invocation is meant to allow the -o and +o options (besides the default --man/--author... options handled out-of-band), but it seems to also enable an unwanted +- option.

Expected behaviour:

myscript: +-: unknown option
opt='?'
typeset -i OPTIND=1
myscript: +-: unknown option
opt='?'
typeset -i OPTIND=1
myscript: +-: unknown option
opt='?'
typeset -i OPTIND=1
opt=+o
OPTARG=1
typeset -i OPTIND=2

Like when invoked with +xxxo.

(with 1.0.10 on Debian forky GNU/Linux amd64)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions