|
|
1.1 root 1: .TH EXPR 1
2: .CT 1 shell
3: .SH NAME
4: expr \- evaluate arguments as an expression
5: .SH SYNOPSIS
6: .B expr
7: .I arg ...
8: .SH DESCRIPTION
9: The arguments are taken as an expression.
10: After evaluation, the result is written on the standard output.
11: Each token of the expression is a separate argument.
12: .PP
13: The operators and keywords are listed below
14: in order of increasing precedence,
15: with equal precedence operators grouped.
16: .TP \w'\f5(\fI\ expr\ \f5)\ 'u
17: .IB expr1 " | " expr2
18: Value is the value of
19: .I expr1
20: if that is neither empty nor 0,
21: otherwise the value of
22: .IR expr2.
23: .TP
24: .IB expr1 " & " expr2
25: Value is the value of
26: .I expr1
27: if neither
28: .I expr1
29: nor
30: .I expr2
31: is empty or 0, otherwise 0.
32: .TP
33: .I expr1 relop expr2
34: .I Relop
35: is one of
36: .L "< <= = != >= >" .
37: Value is 1
38: if the indicated comparison is true, 0
39: if false.
40: The comparison is numeric if both
41: .I expr
42: are integers, otherwise lexicographic.
43: .TP
44: .IB expr1 " + " expr2
45: .br
46: .ns
47: .TP
48: .IB expr1 " - " expr2
49: .br
50: Value is the sum or difference of the (integer) values of
51: .I expr1
52: and
53: .I expr2.
54: .TP
55: .IB expr1 " * " expr2
56: .br
57: .ns
58: .TP
59: .IB expr1 " / " expr2
60: .br
61: .ns
62: .TP
63: .IB expr1 " % " expr2
64: .br
65: Value is the product, quotient, or remainder of the (integer)
66: values of
67: .I expr1
68: and
69: .I expr2.
70: .TP
71: .IB expr " : " regexp
72: Match the string value of
73: .I expr
74: with the regular expression
75: .IR regexp ;
76: regular expression syntax is the same as in
77: .IR ed (1),
78: but matches are anchored at the left.
79: On success a subexpression
80: .BR \e(\| ... \|\e) ,
81: if present in
82: .I regexp,
83: picks out a return value from the matched string.
84: Otherwise,
85: the matching operator yields the number of characters matched
86: (0 on failure).
87: .TP
88: .BI ( " expr " )
89: Parentheses for grouping.
90: .TP
91: .I arg
92: Value is the string
93: .I arg.
94: .PP
95: .SH EXAMPLES
96: .TP
97: .L
98: a=`expr $a + 1`
99: Add 1 to shell variable
100: .IR a .
101: .TP
102: .L
103: expr $a : '.*/\e(.*\e)' '|' $a
104: Same as
105: .LR "basename $a" .
106: .SH "SEE ALSO"
107: .IR sh (1),
108: .IR test (1)
109: .SH DIAGNOSTICS
110: .I Expr
111: returns exit code 0 if the expression is neither null nor 0,
112: 1 if the expression is null or 0, 2 for invalid expressions.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.