help-bash
[Top][All Lists]
Advanced

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

Handling getopt for option without optional argument value


From: lisa-asket
Subject: Handling getopt for option without optional argument value
Date: Fri, 23 Jul 2021 17:49:45 +0200 (CEST)

Things get complicated because people tell you that if you want to handle 

--gnu-long-opts you have to write your own parser.



You say there is getopts.  The job got to be finished, not done half way.

So we can all use the built-in. But you just tell people, don't do long options.


From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: Handling getopt for option without optional argument value
Date: 23/07/2021 17:43:18 Europe/Paris

On Fri, Jul 23, 2021 at 05:17:01PM +0200, lisa-asket@perso.be wrote:
> Tho approach should be to fix getopt if there are problems with it, no?

No. It's an ancient non-standard command. It's a historic artifact.
There is no changing it (because doing so would break scripts).

Check out various man pages:

http://man.openbsd.org/getopt

The getopt utility cannot handle option arguments containing whitespace;
consider using the standard getopts shell built-in instead.


https://www.freebsd.org/cgi/man.cgi?getopt

Arguments containing whitespace or embedded shell metacharacters gener-
ally will not survive intact; this looks easy to fix but is not.
People trying to fix getopt or the example in this manpage should
check the his- tory of this file in FreeBSD.


https://docs.oracle.com/cd/E23823_01/html/816-5165/getopt-1.html#scrolltoc

The getopts command supersedes getopt. For more information, see
NOTES below.

getopt will not be supported in the next major release. For this
release a conversion tool has been provided, namely, getoptcvt. For
more information, see getopts(1) and getoptcvt(1).

getopt does not support the part of Rule 8 of the command syntax
standard (see Intro(1)) that permits groups of option-arguments
following an option to be separated by white space and quoted. [...] To
correct this deficiency, use the getopts command in place of getopt.


The getopts (note the 's') builtin command replaces getopt, and is not
broken. Use that instead. Or, if you need to handle --gnu-long-opts
or -findopts, write your own option parser. Or don't write the program
in bash in the first place. Or STOP FEELING THAT YOU NEED --gnu-long-opts
or -findopts in your program. Just... don't do it.

People make their own lives SO much more complicated than they need to be.
I don't understand why.




reply via email to

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