[Bug 215207] [patch] getopt(1) example mangles command-line arguments with embedded spaces

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sat Dec 24 22:55:48 UTC 2016


Jilles Tjoelker <jilles at FreeBSD.org> changed:

           What    |Removed                     |Added
                 CC|                            |jilles at FreeBSD.org

--- Comment #1 from Jilles Tjoelker <jilles at FreeBSD.org> ---
The patched version ignores getopt(1)'s output except for the number of
iterations of a loop. This drops necessary adjustments made by getopt(1) such
as changing -ab to -a -b.

As noted in the BUGS section of getopt(1), fixing arguments with whitespace and
shell metacharacters is hard. With the current API, it is not possible.

A reasonable solution for shell scripts is to use the getopts builtin instead
of getopt(1). This fixes the problems with special characters and poor error
messages and simplifies the code in the script. The man page could recommend
this more.

If you insist on using something called "getopt" or want to use long options,
an alternative is to use a non-standard mode of the misc/getopt port.

You are receiving this mail because:
You are the assignee for the bug.

More information about the freebsd-bugs mailing list