View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001951 | 1003.1(2024)/Issue8 | Shell and Utilities | public | 2025-10-25 21:48 | 2025-11-14 12:16 |
| Reporter | Love4Boobies | Assigned To | |||
| Priority | normal | Severity | Editorial | Type | Error |
| Status | Resolved | Resolution | Accepted As Marked | ||
| Name | Bogdan Barbu | ||||
| Organization | |||||
| User Reference | |||||
| Section | getopts, EXAMPLES section | ||||
| Page Number | 2982 | ||||
| Line Number | 99728 | ||||
| Interp Status | --- | ||||
| Final Accepted Text | 0001951:0007322 | ||||
| Summary | 0001951: getopts example oversight | ||||
| Description | The example snippet handles ? instead of \?. It still works but only by accident (the ? wildcard still matches the literal question mark returned by getopts) because no other options are handled after it. | ||||
| Desired Action | Change ? to \? | ||||
| Tags | tc1-2024 | ||||
|
|
It seems likely to me that not escaping the ? is intentional. In a script with a large number of options, if there is a mismatch between the list passed to getopts and the list handled in the case statement, it is desirable for an unexpected value of "name" to be reported as a usage error rather than falling through the case statement unhandled. My suggestion is to change the ? to * so that it is clear this is a catch-all (even though it should always be one character). |
|
|
Change ? to * |
|
|
> even though it should always be one character For the record, with the exception of yash's, all getopts implementations I tried at the moment seem to work at byte level, not character level (which make them all except yash non-compliant, though in practice it would be a bad idea to use option characters outside the portable character set). If not, switching to * would be better for the case where LC_CTYPE is different between the getopts invocation and the case construct. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2025-10-25 21:48 | Love4Boobies | New Issue | |
| 2025-10-30 16:58 | geoffclare | Note Added: 0007301 | |
| 2025-11-13 16:27 | geoffclare | Note Added: 0007322 | |
| 2025-11-13 16:28 | geoffclare | Status | New => Resolved |
| 2025-11-13 16:28 | geoffclare | Resolution | Open => Accepted As Marked |
| 2025-11-13 16:28 | geoffclare | Page Number | https://pubs.opengroup.org/onlinepubs/9799919799/utilities/getopts.html => 2982 |
| 2025-11-13 16:28 | geoffclare | Line Number | Idk, I used the web version => 99728 |
| 2025-11-13 16:28 | geoffclare | Interp Status | => --- |
| 2025-11-13 16:28 | geoffclare | Final Accepted Text | => 0001951:0007322 |
| 2025-11-13 16:28 | geoffclare | Tag Attached: tc1-2024 | |
| 2025-11-14 08:22 | stephane | Note Added: 0007326 | |
| 2025-11-14 12:16 | stephane | Note Edited: 0007326 |