1 .\" $NetBSD: expr.1,v 1.10 1997/10/20 08:51:56 enami Exp $
3 .\" Written by J.T. Conklin <jtc@netbsd.org>.
11 .Nd evaluate expression
20 and writes the result on standard output.
22 All operators are separate arguments to the
25 Characters special to the command interpreter must be escaped.
27 Operators are listed below in order of increasing precedence.
28 Operators with equal precedence are grouped within { } symbols.
29 .Bl -tag -width indent
30 .It Ar expr1 Li | Ar expr2
31 Returns the evaluation of
33 if it is neither an empty string nor zero;
34 otherwise, returns the evaluation of
36 .It Ar expr1 Li & Ar expr2
37 Returns the evaluation of
39 if neither expression evaluates to an empty string or zero;
40 otherwise, returns zero.
41 .It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2
42 Returns the results of integer comparison if both arguments are integers;
43 otherwise, returns the results of string comparison using the locale-specific
45 The result of each comparison is 1 if the specified relation is true,
46 or 0 if the relation is false.
47 .It Ar expr1 Li "{+, -}" Ar expr2
48 Returns the results of addition or subtraction of integer-valued arguments.
49 .It Ar expr1 Li "{*, /, %}" Ar expr2
50 Returns the results of multiplication, integer division, or remainder of integer-valued arguments.
51 .It Ar expr1 Li : Ar expr2
58 which must be a regular expression. The regular expression is anchored
59 to the beginning of the string with an implicit
62 expects "basic" regular expressions, see
64 for more information on regular expressions.
66 If the match succeeds and the pattern contains at least one regular
67 expression subexpression
69 the string corresponding to
72 otherwise the matching operator returns the number of characters matched.
73 If the match fails and the pattern contains a regular expression subexpression
74 the null string is returned;
78 Parentheses are used for grouping in the usual manner.
82 The following example adds one to the variable a.
85 The following example returns the filename portion of a pathname stored
86 in variable a. The // characters act to eliminate ambiguity with the
88 .Dl expr "//$a" Li : '.*/\e(.*\e)'
90 The following example returns the number of characters in variable a.
96 utility exits with one of the following values:
97 .Bl -tag -width Ds -compact
99 the expression is neither an empty string nor 0.
101 the expression is an empty string or 0.
103 the expression is invalid.