"Sebastian Kreft" <[EMAIL PROTECTED]> writes:
> I don't know if it is a standard of expr, but I think that is not
> intuitive to write a plus symbol before the string substr if I want
> to get the length of it. I know that is in the help, but I think
> that this shouldn't be necessary.
Traditional Unix reports a syntax error if you omit the "+". E.g., on
Solaris 8:
$ /bin/expr length substr
expr: syntax error
$ /usr/xpg4/bin/expr length substr
expr: syntax error
The "+" is a GNU extension; it avoids the ambiguities involved in
treating strings like "substr" both as operators and as data.
For example:
expr length match = 1
Should this be parsed as "(length match) = 1" or as "length (match =
1)"? Your intuition might go one way, but "expr" might go the other.
For what it's worth, Unix expr reports a syntax error for this 2nd
example as well; GNU expr parses it in the 2nd way.
> I haven't seen the source code of the parsing so much, because I don't know
> if this behaviour is a standard or not.
Both GNU expr and Unix expr conform to the POSIX standard, as far as I
know, since POSIX says only "The use of string arguments length,
substr, index, or match produces unspecified results." See
<http://www.opengroup.org/onlinepubs/000095399/utilities/expr.html>.
My own feeling is that portable programs should not use "length",
"substr", "index", or "match", as they cause too much trouble. You
can use Awk if you want string processing.
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils