Bug #1237
closed
patch to add getopt parsing to expr
Added by josepht almost 16 years ago.
Updated over 15 years ago.
Description
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.
Joe
Files
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
anyway.
Joerg
Since POSIX requires arguments beginning with '-' to be options
shouldn't the following result in an error?
expr -d=zzz : '.*=\(.*\)'
Where:
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.
Thanks,
Joe
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.
Joerg
What about this?
Guideline 14:
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.
Joe
Doesn't apply. SUS leaves it open whether or not expr supports options.
It does require expr to support --. Consider "expr -1".
Joerg
Okay. Here's the new patch.
Joe
was committed -> ee2af4a46fc2ddef3a589ee9d5b58aa1c1f923bc
Also available in: Atom
PDF