[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[coreutils] Re: expr option interpretation changes
From: |
Nelson H. F. Beebe |
Subject: |
[coreutils] Re: expr option interpretation changes |
Date: |
Tue, 14 Oct 2008 15:05:13 -0600 (MDT) |
I agree with a previous poster that the altered behaviour of expr in
coreutils-7.0 as a result of using getopt() for option parsing is
acceptable, and consistent with many other utilities, and with GNU and
POSIX interpretation of a double-hyphen option.
Here is another problem area with expr (in general, not just the GNU
version). Consider these two similar cases:
expr -1 + 3
expr ' -1' + 3
To a human, both of these should evaluate to 2.
Apple Mac OS X, DEC Alpha OSF/1, OpenBSD, Sun Solaris 10, SGI IRIX
native expr, and GNU/coreutils 7.0 produce 2 for the first, but
complain "expr: non-numeric argument:" for the second.
On FreeBSD, the reverse happens:
% /bin/expr -1 + 3
expr: illegal option -- 1
usage: expr [-e] expression
% /bin/expr ' -1' + 3
2
On Minix and NetBSD, both are accepted:
% /bin/expr -1 + 3
2
% /bin/expr ' -1' + 3
2
The proposed double-hyphen style
/bin/expr -- -1 + 3
works on most of the cited systems, but fails on Minix and OpenBSD:
% /bin/expr -- -1 + 3
expr: syntax error
I patched another local script this morning that got an error from the
new coreutils version of expr, using a leading zero addition, like
this,
expr 0 + $m + $n
to hide the possibility of $m being negative. This subterfuge works
on all systems.
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- University of Utah FAX: +1 801 581 4148 -
- Department of Mathematics, 110 LCB Internet e-mail: address@hidden -
- 155 S 1400 E RM 233 address@hidden address@hidden -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------
- [coreutils] Re: expr option interpretation changes,
Nelson H. F. Beebe <=