> Date: Thu, 21 Mar 2002 23:55:50 GMT
> From: yyyyyyy@xxxxxxxxxxx
>
> the normative text describing the expr utility does not
> state that it obeys the Utility Syntax Guidelines, and I am not
> aware of any common implementation which will accept a "--"
> argument as suggested in the informative text,
As it happens, I submitted a patch to GNU expr on this subject a
few months ago, in preparation for POSIX 1003.1-2001:
2001-06-20 Paul Eggert <yyyyyy@xxxxxxxxxxx>
* src/expr.c (main): Handle a leading "--" option as
per the POSIX Utility Syntax Guidelines.
This patch is installed in the GNU expr CVS sources now, and is
scheduled to appear in the next release.
> b) Delete the problematic paragraph from the APPLICATION NOTES
> section, and under OPTIONS add language prohibiting implementations
> from adding options as an extension,
(b) would prohibit GNU expr's ordinary behavior, because (b) would
require "expr --help" and "expr --version" to output the strings
"--help" and "--version", respectively. The latest public release of
GNU expr would conform to (b) if you set the POSIXLY_CORRECT
environment variable, but the latest CVS version relies on the
APPLICATION USAGE section of POSIX 1003.1-2001 and removes this
behavior wart: "expr --help" outputs a help message even in
POSIX-conforming mode.
What a mess, huh?
Instead of your (a) and (b), how about the following change (c)
instead? (c) would bless all the usages described above, and it
reflects common gotchas in writing portable shell scripts. (c)
changes only the APPLICATION USAGE section, so it is a more
conservative change to the standard than (a) and (b) are.
c)
In expr, under APPLICATION USAGE, change:
Therefore, the conforming application must employ the "--" construct
of Guideline 10 of the Base Definitions volume of IEEE Std
1003.1-2001, Section 12.2, Utility Syntax Guidelines to protect its
operands if there is any chance the first operand might be a negative
integer (or any string with a leading minus).
to:
Therefore, a conforming application must protect its operands if
there is any chance the first operand might be a negative integer
(or any string with a leading minus). The 'expr' command is not
required to conform to the Base Definitions volume of IEEE Std
1003.1-2001, Section 12.2, Utility Syntax Guidelines, so conforming
applications must not assume that the "--" construct of Guideline
10 can be used to protect operands with leading minus.
A portable way to protect integer operands with leading minus is to
parenthesize them. For example, instead of this:
expr "$integer" + 1
a conforming application might use this:
expr '(' "$integer" ')' + 1
as this will work correctly even if "$integer" is "-1".
A portable way to protect string operands is to prefix them with
"X". For example, instead of this:
expr "$string" : '\(.*\)-'
a conforming application might use this:
expr "X$string" : 'X\(.*\)-'
as this will work correctly even if "$string" is "-". In general,
string operands need this kind of protection even if they are not
the first operand of 'expr', because a portable string operand must
not be an expression operator symbol or an integer.
|