Eric Blake wrote: > According to Pádraig Brady on 10/14/2008 3:47 AM: >>> With native versions of expr, and expr from GNU coreutils prior to >>> version 7.0, the expansion of lscmd usually begins "-rw-r--r--", but >>> the leading hyphen does not cause the word to be treated as an option. >> I think that was an unintended change introduced when adding getopt to expr: >> http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=f65cafd67b33009d23f940968bbe7f9a08d6fe13 > > Unintended or not, getopt's side effect of complaining about unrecognized > options is necessary for standard compliance (ie. all earlier versions of > coreutils had a bug in this area), so we should not revert it.
Quoting the spec: "Also note that this volume of IEEE Std 1003.1-2001 permits implementations to extend utilities. The expr utility permits the integer arguments to be preceded with a unary minus. This means that an integer argument could look like an option. 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)." Does the above mean expr must support -- or that apps must use -- I think it's the former, and this is what the expr code tries to do. I.E. it does try to treat non options starting with - as part of the expression. However it gets it wrong in the case of chained short args as seen here: localhost:~/git/coreutils/src$ expr -oh : -oh 3 localhost:~/git/coreutils/src$ expr -- -oh : -oh 3 localhost:~/git/coreutils/src$ ./expr-new -oh : -oh ./expr: syntax error localhost:~/git/coreutils/src$ ./expr-new -o : -o 2 localhost:~/git/coreutils/src$ ./expr-new -- -oh : -oh 3 cheers, Pádraig. p.s. why does expr need the --bignum option anyway? Shouldn't we just use it by default if available. _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils