patch to add getopt parsing to expr
Here's a patch to add getopt(3) support to expr so that -- is accepted as
required by POSIX. This was pointed out by vstemen on IRC. I'll
commit sometime after the release if there are no objections.
The use of getopt here is wrong. Besides, using getopt is taking a
sledgehammer to crack a nut. Attached is the corresponding fix for
NetBSD, the explicit check for having at least one argument is better
Since POSIX requires arguments beginning with '-' to be options
shouldn't the following result in an error?
expr -d=zzz : '.*=\(.*\)'
expr -- -d=zzz : '.*=\(.*\)'
should be the correct usage. I opted to use getopt() since FreeBSD's
expr accepts -e. The "-" was inadvertently left in the patch.
No. POSIX only says that -- has to be supported to disable the use of
options. It doesn't say that options have to be used.
What about this?
If an argument can be identified according to Guidelines 3 through
10 as an option, or as a group of options without option-arguments
behind one '-' delimiter, then it should be treated as such.
Doesn't apply. SUS leaves it open whether or not expr supports options.
It does require expr to support --. Consider "expr -1".
Okay. Here's the new patch.
was committed -> ee2af4a46fc2ddef3a589ee9d5b58aa1c1f923bc
Also available in: Atom