COHERENT manpages

This page displays the COHERENT manpage for expr [Compute a command-line expression].

List of available manpages
Index


expr -- Command

Compute a command-line expression
expr argument ...

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 command 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 numerical 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  associate left  to right
except the  unary operators `!',  `-', and `len', which  associate right to
left.  The spaces  shown are significant - they separate  the tokens of the
expression.

{ expr1, expr2, expr3 }
     Return  expr2  if  expr1  is  logically  true,  and  expr3  otherwise.
     Alternatively, { expr1 , expr2 }  is equivalent to { expr1 , expr2 , 0
     }.

expr1 | expr2
     Return expr1 if it is true, expr2 otherwise.

expr1 & expr2
     Return expr1 if both are true, zero otherwise.

expr1 relation expr2
     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).

expr1 + expr2

expr1 - expr2
     Add or  subtract the integer arguments.  The  expression is invalid if
     either expr is not a number.

expr1 * expr2

expr1 / expr2

expr1 % expr2
     Multiply, divide, or  take remainder of the arguments.  The expression
     is invalid if either expr is not numeric.

expr1 : expr2
     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.

len expr
     Return the length of expr. It behaves like strlen (see string). len is
     a reserved word in expr.

!expr
     Perform logical negation: return zero if expr is true, one otherwise.

-expr
     Unary  minus: return  the negative  of its  integer argument.   If the
     argument is non-numeric the expression is invalid.

( expr )
     Return  the expr.  The parentheses allow  grouping expressions  in any
     desired way.

The following operators have special meanings  to the shell sh, and must be
quoted to be interpreted correctly: { } ( ) < > &amp; | *.

See Also

commands,
ed,
ksh,
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.