View Issue Details

IDProjectCategoryView StatusLast Update
00019511003.1(2024)/Issue8Shell and Utilitiespublic2025-10-30 16:58
ReporterLove4Boobies Assigned To 
PrioritynormalSeverityEditorialTypeError
Status NewResolutionOpen 
NameBogdan Barbu
Organization
User Reference
Sectiongetopts, EXAMPLES section
Page Numberhttps://pubs.opengroup.org/onlinepubs/9799919799/utilities/getopts.html
Line NumberIdk, I used the web version
Interp Status
Final Accepted Text
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 \?
TagsNo tags attached.

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

Issue History

Date Modified Username Field Change
2025-10-25 21:48 Love4Boobies New Issue
2025-10-30 16:58 geoffclare Note Added: 0007301