|
|
1.1 root 1:
2:
3: expr Command expr
4:
5:
6:
7:
8: Compute a command line expression
9:
10: eexxpprr _a_r_g_u_m_e_n_t ...
11:
12: The arguments to expr form an expression. expr evaluates the
13: expression and writes the result on the standard output. Among
14: other uses, expr lets the user perform arithmetic in shell com-
15: mand files.
16:
17: Each argument is a separate token in the expression. An argument
18: has a logical value `false' if it is a null string or has numeri-
19: cal value zero, `true' otherwise. Integer arguments consist of
20: an optional sign followed by a string of decimal digits. The
21: range of valid integers is that of signed long integers. No
22: check is made for overflow or illegal arithmetic operations.
23: Floating point numbers are not supported.
24:
25: The following list gives each expr operator and its meaning. The
26: list is in order of increasing operator precedence; operators of
27: the same precedence are grouped together. All operators as-
28: sociate left to right except the unary operators `!', `-', and
29: `lleenn', which associate right to left. The spaces shown are sig-
30: nificant - they separate the tokens of the expression.
31:
32: { _e_x_p_r_1, _e_x_p_r_2, _e_x_p_r_3 }
33: Return expr2 if expr1 is logically true, and expr3 other-
34: wise. Alternatively, { _e_x_p_r_1 , _e_x_p_r_2 } is equivalent to {
35: _e_x_p_r_1 , _e_x_p_r_2 , 00 }.
36:
37: _e_x_p_r_1 | _e_x_p_r_2
38: Return expr1 if it is true, expr2 otherwise.
39:
40: _e_x_p_r_1 & _e_x_p_r_2
41: Return expr1 if both are true, zero otherwise.
42:
43: _e_x_p_r_1 _r_e_l_a_t_i_o_n _e_x_p_r_2
44: Where relation is one of <, <=, >, >=, ==, or !=, return one
45: if the relation is true, zero otherwise. The comparison is
46: numeric if both arguments can be interpreted as numbers,
47: lexicographic otherwise. The lexicographic comparison is
48: the same as strcmp (see string).
49:
50: _e_x_p_r_1 + _e_x_p_r_2
51: _e_x_p_r_1 - _e_x_p_r_2
52: Add or subtract the integer arguments. The expression is
53: invalid if either expr is not a number.
54:
55: _e_x_p_r_1 * _e_x_p_r_2
56: _e_x_p_r_1 / _e_x_p_r_2
57: _e_x_p_r_1 % _e_x_p_r_2
58: Multiply, divide, or take remainder of the arguments. The
59: expression is invalid if either expr is not numeric.
60:
61:
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
67:
68:
69: expr Command expr
70:
71:
72:
73: _e_x_p_r_1 : _e_x_p_r_2
74: Match patterns (regular expressions). expr2 specifies a
75: pattern in the syntax used by ed. It is compared to expr1,
76: which may be any string. If the \(...\) pattern occurs in
77: the regular expression the matching operator returns the
78: matched field from the string; if there is more than one
79: \(...\) pattern the extracted fields are concatenated in the
80: result. Otherwise, the matching operator returns the number
81: of characters matched.
82:
83: lleenn _e_x_p_r
84: Return the length of expr. It behaves like strlen (see
85: string). len is a reserved word in expr.
86:
87: !_e_x_p_r
88: Perform logical negation: return zero if expr is true, one
89: otherwise.
90:
91: -_e_x_p_r
92: Unary minus: return the negative of its integer argument.
93: If the argument is non-numeric the expression is invalid.
94:
95: ( _e_x_p_r )
96: Return the expr. The parentheses allow grouping expressions
97: in any desired way.
98:
99: Several operators have special meanings to the shell sh, and must
100: be quoted to be interpreted correctly. The characters that must
101: be quoted are { } ( ) < > & | *.
102:
103: ***** See Also *****
104:
105: commands, ed, sh, test
106:
107: ***** Notes *****
108:
109: expr returns zero if the expression is true, one if false, and
110: two if an error occurs. In the latter case an error message is
111: also printed.
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130: COHERENT Lexicon Page 2
131:
132:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.