The operators and keywords are listed below.
The list is in order of increasing precedence,
with equal precedence operators grouped.
|
expr | expr |
|
yields the first
expr if it is neither null nor '0', otherwise
yields the second
expr. |
expr & expr |
|
yields the first
expr if neither
expr is null or '0', otherwise yields '0'.
|
expr relop expr |
|
where
relop is one of < <= = != >= >,
yields '1' if the indicated comparison is true, '0' if false.
The comparison is numeric if both
expr are integers, otherwise lexicographic.
|
expr + expr |
|
expr - expr
addition or subtraction of the arguments.
|
expr * expr |
|
expr / expr
expr % expr
multiplication, division, or remainder of the arguments.
|
expr : expr |
|
The matching operator compares the string first argument
with the regular expression second argument.
Regular expression syntax is the same as that of
ed(1);
/usr/5bin/expr uses simple regular expressions,
/usr/5bin/posix/expr, /usr/5bin/posix2001/expr, and
/usr/5bin/s42/expr use basic regular expressions.
The
\(...\)
pattern symbols can be used to select a portion of the
first argument.
Otherwise,
the matching operator yields the number of characters matched
('0' on failure).
|
match expr expr |
|
Same as
expr : expr. |
( expr ) |
|
parentheses for grouping.
|
string |
Yields itself
unless it is part of a larger expression.
With
/usr/5bin/posix/expr and
/usr/5bin/posix2001/expr, all
strings that form valid decimal numbers
are converted to the canonical form.
|
The following operators are supported only by
/usr/5bin/s42/expr or if the
SYSV3 environment variable is set:
|
length string |
|
Returns the number of characters in
string. |
substr string index count |
|
Returns a string that consists of
count characters
beginning at position
index of
string (starting at 1).
|
index string set |
|
Returns the index in
string (starting at 1) of the first occurrence
of one of the characters in
set, or 0 if no character is found.
|
|