View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002016 | 1003.1(2024)/Issue8 | Base Definitions and Headers | public | 2026-12-01 23:00 | 2026-12-03 01:32 |
| Reporter | romanzilka | Assigned To | |||
| Priority | normal | Severity | Comment | Type | Enhancement Request |
| Status | New | Resolution | Open | ||
| Name | Roman Žilka | ||||
| Organization | |||||
| User Reference | |||||
| Section | 12.2 (Utility Syntax Guidelines) | ||||
| Page Number | 0 | ||||
| Line Number | 0 | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0002016: Utility Syntax Guidelines: Include long options as in GNU's getopt_long() | ||||
| Description | I propose extending subchapter 12.2 of the Base Definitions to include "long options", as implemented by the GNU C Library. Technical specifics: https://www.sourceware.org/glibc/manual/latest/html_node/Getopt-Long-Options.html https://man7.org/linux/man-pages/man3/getopt_long.3.html https://man7.org/linux/man-pages/man3/getopt_long_only.3.html If implemented, the function getopt_long() should be simultaneously incorporated into unistd.h (not getopt.h, as seen in glibc). The functionality of getopt_long_only() is equally desirable, but I suggest transforming it into a feature of getopt_long(), if possible. A feature which doesn't change the behavior of getopt_long() from the prespective of existing programs (expanding the expressiveness of has_arg in struct option, perhaps). Rationale: 1. Expanding the space of available options allows the application to assign more fitting options to its features. 2. Long options' names usually suggest their meaning, which is helpful to inexperienced and occasional users of the application. That includes the use of the long options in documentation. 3. Long options with no short counterparts can serve as a safety measure, making it very hard for the application user to activate a feature by accident. 4. The application may require more options than the alphanumeric repertoire of the Portable Character Set affords. 5. Long options with no short counterparts may be employed as markers of rarely used functionality, which may alleviate the difficulty of searching for an option in a list of all options. | ||||
| Desired Action | See Description. The present goal of this issue is to garner opinions and reach a yes/no verdict. | ||||
| Tags | No tags attached. | ||||
|
|
There are implementation differences am:ong them; eg https://man.openbsd.org/getopt_long I do not really grasp your 3., your 4. is not true for POSIX, having failed myself often i do not think 2. is true except you write entire sentences at times, and 5., well. Having said that i am all for supporting long options. But definetely not as GNU C lib does it; reordering, optional arguments, i speak against both of these two. Having said that, II., personally i use my own getopt implementation, which does it differently. "check-and-exit;e;" N_("note mail presence (of -L) via exit status"), And then there are things like git (iirc) and also certain OpenBSD infrastructure servers (ditto) which i think directly call functions or parse integers out into storage, i think busybox also has something similar, you know, ... waaayy more sophisticated; one could argue that moving as much computation as possible into a generic getopt is a real safety measure... |
|
|
romanzilka> If implemented, the function getopt_long() should be simultaneously incorporated into unistd.h (not getopt.h, as seen in glibc). I don't think that makes much sense, all existing code is using getopt.h for the various implementations of getopt_long(). romanzilka> The functionality of getopt_long_only() is equally desirable, but I suggest transforming it into a feature of getopt_long(), if possible. A feature which doesn't change the behavior of getopt_long() from the prespective of existing programs (expanding the expressiveness of has_arg in struct option, perhaps). Not really sure why you'd want to merge the two, the wording can split behavior between the two when needed, and implementations are free to have one being a wrapper of another, or both getopt_long() and getopt_long_only() being wrappers of common internal code. steffen> But definetely not as GNU C lib does it; reordering, optional arguments, i speak against both of these two. Reordering typically ends up disabled with POSIXLY_CORRECT anyway, which is the one that would make sense to standardize in POSIX. As for optional argument support, after poking at it (on musl and glibc), I think it's fine when specific to a long option as the equal sign form (ie. --foo=bar) is required to pass an option-argument. While optional-arguments for short-options are an ambiguous mess. (Somehow only one I've seen documenting that equal-sign restriction is IBM z/OS, but maybe I've missed it in the other manpages) Manpages for other systems as well: - https://man.openbsd.org/getopt_long - https://man.freebsd.org/cgi/man.cgi?getopt_long - https://man.dragonflybsd.org/?command=getopt_long§ion=ANY - https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getopt_long.3.html - https://illumos.org/man/3C/getopt_long - https://www.ibm.com/docs/en/zos/3.2.0?topic=functions-getopt-long-command-long-option-parsing (somehow IBM z/OS has it, apparently not IBM AIX) |
|
|
I forgot to mention: if the Base Definitions change, getopts in Shell Utilities will need to adapt, not only System Interfaces. steffen> Rationale item 3: this can be "--i-know-what-im-doing" in a utility which can have irreversible effects. Or something more subtle, which still doesn't get a short option to make it harder for the user to shoot themseves in the foot when they accidentally type "-a" instead of "-s" or "-asd" instead of "-ad". Real-world examples are GNU coreutils' "rm --no-preserve-root" and Debian's "get-apt --allow-remove-essential". Rationale item 4: Utility Syntax Guidelines say that an option should be an alphanumeric character from the portable charset. That may not be enough options. lanodan> Existing code won't break if POSIX puts getopt_long() in unistd.h, POSIX implementations can adapt easily. Creating a new header is a bad idea IMO. There's the closely related getopt() function already in existence, and it is placed in unistd.h. I also wonder why getsubopt() is separated from getopt() in stdlib.h. Moreover, POSIX's new function may end up having a different name, like getopt_long_posix(). Because it may turn out that nothing can be compatible with all of the existing getopt_long()s simultaneously or POSIX may choose not to be compatible. Of course, POSIX may choose not to care. I'd like for getopt_long_only() not to exist as a separate function, because its difference from getopt_long() is very minimal and headers shouldn't become polluted by functions which do nearly the same thing. It will be another matter, of course, if it isn't possible to unite the two functions. |
|
|
ok sorry, but this is shorter than desired; my original post was timed out by Mantis. (Wasn't this fixed? I restart preparing locally.) No. It *is* enough for POSIX utilities. Implementations can do whatever they want, i for example do
Any printable ASCII (7-bit) character except hyphen-minus \c{-} may be used as a short option.
And i do not bite your "shoot yourself in the foot". Not to quote Chet Ramey with his ~"bash is a sharp weapon". But for example in what possibly could be called "worm month" of 1988, in the thread "fixing rm * (was: Worm/Passwords)" it was said
The standard trick for csh is
alias rm "/bin/rm -i"
which is why i *think* kre does not like aliases :) https://ftp.math.utah.edu/pub/mirrors/minnie.tuhs.org/Unix_Usenet/comp.unix.wizards/1988-November/033598.html I think in the most of many cases the POSIX standard implements a least common denominator of what actually exists in the wild. So maybe there is a reasoning for *why* the set of usable bytes is so restricted? I do not look myself! But it seems likely that one can use that set of characters and have a go with getopt implementations without headaches. Maybe it is this. Having said all that, i more often than not got issues declined even for really useful functionality that i work with "on UNIX" for many years, and could not live without. Or kept lingering. |
|
|
(i repeat i have nothing against this.) To add that the "=" separator is *not* necessary for getopt_long? So if it is like that then with "xy --opt arg", "xy --opt=arg" and "xy --opt", how can i decisively decide when the next argument is an option or argument? Especially if that starts with a hyphen-minus? By the way. The old hands, they also had another very smart trick to prevent misinterpretation, i think it involved hyphen-minus somehow, i could not find it in my archives :-(( (which is why Mantis timed out, likely). I would love to hear this again. Thank you. |
|
|
> To add that the "=" separator is *not* necessary for getopt_long? It is needed *only* when optional_argument is used, so --opt arg only works when it's in required_argument mode while --opt=arg works with both. Which sounds okay to me although might be a bit surprising to users, specially if some utility would change an option from required_argument to optional_argument (maybe little-to-no software did that, or would use another option name instead). (Also I hit the mantis security token timeout in my previous comment, thankfully browser's back button worked okay) |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-12-01 23:00 | romanzilka | New Issue | |
| 2026-12-02 00:45 | steffen | Note Added: 0007573 | |
| 2026-12-02 02:29 | lanodan | Note Added: 0007574 | |
| 2026-12-02 02:30 | lanodan | Note Edited: 0007574 | |
| 2026-12-02 11:45 | romanzilka | Note Added: 0007579 | |
| 2026-12-02 19:21 | steffen | Note Added: 0007582 | |
| 2026-12-02 19:28 | steffen | Note Added: 0007583 | |
| 2026-12-03 01:31 | lanodan | Note Added: 0007584 | |
| 2026-12-03 01:32 | lanodan | Note Edited: 0007584 |