View Issue Details

IDProjectCategoryView StatusLast Update
00019511003.1(2024)/Issue8Shell and Utilitiespublic2025-11-14 12:16
ReporterLove4Boobies Assigned To 
PrioritynormalSeverityEditorialTypeError
Status ResolvedResolutionAccepted As Marked 
NameBogdan Barbu
Organization
User Reference
Sectiongetopts, EXAMPLES section
Page Number2982
Line Number99728
Interp Status---
Final Accepted Text0001951:0007322
Summary0001951: getopts example oversight
DescriptionThe 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 ActionChange ? to \?
Tagstc1-2024

Activities

geoffclare

2025-10-30 16:58

manager   bugnote:0007301

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).

geoffclare

2025-11-13 16:27

manager   bugnote:0007322

Change ? to *

stephane

2025-11-14 08:22

reporter   bugnote:0007326

Last edited: 2025-11-14 12:16

> 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.

Issue History

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