|
|
coherent
expr Command expr
Compute a command line expression
eexxpprr _a_r_g_u_m_e_n_t ...
The arguments to expr form an expression. expr evaluates the
expression and writes the result on the standard output. Among
other uses, expr lets the user perform arithmetic in shell com-
mand files.
Each argument is a separate token in the expression. An argument
has a logical value `false' if it is a null string or has numeri-
cal value zero, `true' otherwise. Integer arguments consist of
an optional sign followed by a string of decimal digits. The
range of valid integers is that of signed long integers. No
check is made for overflow or illegal arithmetic operations.
Floating point numbers are not supported.
The following list gives each expr operator and its meaning. The
list is in order of increasing operator precedence; operators of
the same precedence are grouped together. All operators as-
sociate left to right except the unary operators `!', `-', and
`lleenn', which associate right to left. The spaces shown are sig-
nificant - they separate the tokens of the expression.
{ _e_x_p_r_1, _e_x_p_r_2, _e_x_p_r_3 }
Return expr2 if expr1 is logically true, and expr3 other-
wise. Alternatively, { _e_x_p_r_1 , _e_x_p_r_2 } is equivalent to {
_e_x_p_r_1 , _e_x_p_r_2 , 00 }.
_e_x_p_r_1 | _e_x_p_r_2
Return expr1 if it is true, expr2 otherwise.
_e_x_p_r_1 & _e_x_p_r_2
Return expr1 if both are true, zero otherwise.
_e_x_p_r_1 _r_e_l_a_t_i_o_n _e_x_p_r_2
Where relation is one of <, <=, >, >=, ==, or !=, return one
if the relation is true, zero otherwise. The comparison is
numeric if both arguments can be interpreted as numbers,
lexicographic otherwise. The lexicographic comparison is
the same as strcmp (see string).
_e_x_p_r_1 + _e_x_p_r_2
_e_x_p_r_1 - _e_x_p_r_2
Add or subtract the integer arguments. The expression is
invalid if either expr is not a number.
_e_x_p_r_1 * _e_x_p_r_2
_e_x_p_r_1 / _e_x_p_r_2
_e_x_p_r_1 % _e_x_p_r_2
Multiply, divide, or take remainder of the arguments. The
expression is invalid if either expr is not numeric.
COHERENT Lexicon Page 1
expr Command expr
_e_x_p_r_1 : _e_x_p_r_2
Match patterns (regular expressions). expr2 specifies a
pattern in the syntax used by ed. It is compared to expr1,
which may be any string. If the \(...\) pattern occurs in
the regular expression the matching operator returns the
matched field from the string; if there is more than one
\(...\) pattern the extracted fields are concatenated in the
result. Otherwise, the matching operator returns the number
of characters matched.
lleenn _e_x_p_r
Return the length of expr. It behaves like strlen (see
string). len is a reserved word in expr.
!_e_x_p_r
Perform logical negation: return zero if expr is true, one
otherwise.
-_e_x_p_r
Unary minus: return the negative of its integer argument.
If the argument is non-numeric the expression is invalid.
( _e_x_p_r )
Return the expr. The parentheses allow grouping expressions
in any desired way.
Several operators have special meanings to the shell sh, and must
be quoted to be interpreted correctly. The characters that must
be quoted are { } ( ) < > & | *.
***** See Also *****
commands, ed, sh, test
***** Notes *****
expr returns zero if the expression is true, one if false, and
two if an error occurs. In the latter case an error message is
also printed.
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.