Bug 4690

Summary: getopt_long "--arg=val" and "--arg val" are not the same for "optional_argument"
Product: glibc Reporter: David <david>
Component: manualAssignee: Roland McGrath <roland>
Severity: enhancement CC: aj, glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description David 2007-06-22 19:00:36 IST
When doing long opt processing, --arg=val and --arg val are interchangeable for
either no_argument or required_argument.  However when using optional_argument,
optarg is set only if the form --arg=val is used.  If the form --arg val is used
then the val is reported as an unknown argv option.

Granted that it may be a vague choice in determining that val is intended for
--arg vs. a value of it's own and therefore best left to the single form of
--arg=val, but all documentation related to getopt() and family refers to the
two forms being interchangeable.

I would like to request future releases of glibc document this in their online
manuals and man pages.

Thank you :)
Comment 1 Ulrich Drepper 2007-06-22 19:09:58 IST
That's how it has to be.  There will be no change.
Comment 2 David 2007-06-22 19:16:46 IST
It "has to be" undocumented?

Perhaps you simply skimmed over this request.  Is it really a policy to not
document something?

It would be nice if the documentation stated that the two forms are
interchangeable except when using /optional_argument/ where --arg=val is the
only acceptable form because --arg val is entirely ambiguous.

It's a simple matter of correcting the documentation to reflect the actual
implementation in glibc.

Please reconsider adding this small note of distinction to the documentation.
Comment 3 Roland McGrath 2007-06-22 19:21:45 IST
Moving to manual
Comment 4 Jakub Jelinek 2007-07-02 15:38:55 IST
Can you cite where you saw the two forms are interchangeable?

E.g. man getopt:
A long option normally begins with `--' followed by the long option name.  If
the  option  has  a  required
argument,  it may be written directly after the long option name, separated by
`=', or as the next argument
(ie. separated by whitespace on the command line).  If the option has an 
optional  argument,  it  must  be
written  directly  after the long option name, separated by `=', if present (if
you add the `=' but nothing
behind it, it is interpreted as if no argument was present; this is a slight 
bug,  see  the  BUGS).
Comment 5 Andreas Jaeger 2012-04-08 09:51:04 IST
No reaction to Jakub's question for several years, thus closing it.

Feel free to reopen after providing the answer.
Comment 6 Jackie Rosen 2014-02-16 19:20:28 IST Comment hidden (spam)