Bug 203279 - /bin/expr operator : fails when the string has a leading hyphen.
Summary: /bin/expr operator : fails when the string has a leading hyphen.
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-23 09:58 UTC by egilb
Modified: 2015-10-18 19:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description egilb 2015-09-23 09:58:51 UTC
expr on other *NIX versions seems to handle a leading hyphen in the text string.
On FreeBSD, the hyphen is parsed as an illegal option:

/bin/expr '-XXabs' : '.*\(aa*\)'
expr: illegal option -- X
expr: usage: expr [-e] expression

A trivial workaround is to use grouping:

/bin/expr \( '-XXabs' : '.*\(aa*\)' \)
a
Comment 1 Jilles Tjoelker freebsd_committer 2015-10-18 19:25:38 UTC
If options that take an option-argument of ":" can be excluded forever, a simple workaround would be to skip option processing if there are 3 arguments (excluding argv[0]) and the second argument is ":".

A stronger form of only treating "--" and "-e" as options would prevent adding any more options without compatibility problems.

Perhaps this is acceptable, since expr is not a utility where major extensions are expected.