Content-type: text/html; charset=UTF-8
expr operand...
( ) | & = > >= < <= != + - * / % :
and the symbols integer and string in the table are provided as separate arguments to expr.
|
The ':' matching operator shall compare the string resulting from the evaluation of expr1 with the regular expression pattern resulting from the evaluation of expr2. Regular expression syntax shall be that defined in the Base Definitions volume of POSIX.1-2008, Section 9.3, Basic Regular Expressions, except that all patterns are anchored to the beginning of the string (that is, only sequences starting at the first character of a string are matched by the regular expression) and, therefore, it is unspecified whether '^' is a special character in that context. Usually, the matching operator shall return a string representing the number of characters matched ('0' on failure). Alternatively, if the pattern contains at least one regular expression subexpression "[\(...\)]", the string matched by the back-reference expression "\1" shall be returned. If the back-reference expression "\1" does not match, then the null string shall be returned.
A string argument is an argument that cannot be identified as an integer argument or as one of the expression operator symbols shown in the OPERANDS section.
The use of string arguments length, substr, index, or match produces unspecified results.
The following sections are informative.
expr $a = '='
looks like:
expr = = =
as the arguments are passed to expr (and they all may be taken as the '=' operator). The following works reliably:
expr X$a = X=
Also note that this volume of POSIX.1-2008 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 POSIX.1-2008,
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).
|