Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15370

Re: Wrong explanation of getopts

From Roland Illig <roland.illig@gmx.de>
Newsgroups gnu.bash.bug
Subject Re: Wrong explanation of getopts
Date 2019-09-15 23:17 +0200
Message-ID <mailman.306.1568582232.2190.bug-bash@gnu.org> (permalink)
References <0bc4f0f2-863d-5c42-76d8-857f74a1d8fa@gmx.de> <CAOSMAutc4KFan0Rorc7TgQVneRovpe21m+yi8nqwk=CBR5cwWw@mail.gmail.com> <3f5b0add-0389-318d-519f-d8e1c2c78cdd@gmx.de>

Show all headers | View raw


Am 15.09.2019 um 22:38 schrieb Eduardo Bustamante:
> On Sun, Sep 15, 2019 at 12:58 PM Roland Illig <roland.illig@gmx.de> wrote:
>>
>> The help text of getopts says:
>>
>>>   Getopts normally parses the positional parameters ($0 - $9), but if
>>>   more arguments are given, they are parsed instead.
> (...)
>> The "instead" in "they are parsed instead" is totally wrong. $1 to $9
>> are always parsed, no matter if there are more than 10 positional
>> parameters or not.
>
> It's not wrong.

Ok, maybe not strictly wrong, but still misleading. In my first try to
read the documentation, and I really did read with good intentions, I
thought the "more" would refer to the "more than $9", and with that
interpretation in mind, the "instead" is clearly wrong.

>> $ getopts
>> getopts: usage: getopts optstring name [arg]
>
> It's referring to the fact that you can explicitly pass a set of
> parameters to `getopts' (i.e. the `[arg]' part), instead of it using
> the script's positional parameters (i.e. $@).

$@ also doesn't include $0. What does $0 have to do with getopts?

In my opinion, the help should read like this:

getopts: getopts optstring name [args]
    Parse option arguments.

    ...

    If ARGS are given, they are parsed. Otherwise the usual positional
    parameters $@ are parsed instead.

The changes are that "arg" is renamed to "args", and it is referred to
unambiguously by saying ARGS in the main text. I also left out the word
"more" since it was the main source of my confusion.

In other parts of the help, repeated arguments are written as [ARG ...]
instead of [ARGS]. For consistency, the same pattern could be used here
as well. In that case, the text should be "If ARGs are given, ...".

Roland

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Wrong explanation of getopts Roland Illig <roland.illig@gmx.de> - 2019-09-15 23:17 +0200

csiph-web