2 .SH NAME \" Copyright (C) 1989 by Kenneth Almquist.
3 expr, test, [ \- evaluate expressions
16 evaluates the expression and prints the result.
18 evaluates the expression without printing the result.
20 command is a synonym for
22 when invoked under this name
25 must be a ``]'', which is deleted and not considered part of the expression.
27 Three data types may occur in the
29 string, integer, and boolean.
30 The rules for conversion are as follows:
36 \fIstring\fR\->\fIinteger\fR Done via
39 \fIinteger\fR\->\fIstring\fR Convert to decimal representation.
41 \fIstring\fR\->\fIboolean\fR "" \-> false, everything else to true.
43 \fIboolean\fR\->\fIstring\fR false \-> "", true \-> "true".
45 \fIinteger\fR\->\fIboolean\fR 0 \-> false, everything else to true.
47 \fIboolean\fR\->\fIinteger\fR false \-> 0, true \-> 1.
52 which is not a legal operator is treated as a string operand of type
57 is omitted, the result is false.
59 We now list the operators. The syntax
62 \fIinteger\fB op \fIinteger\fR \-> \fIboolean\fB (3)\fR
64 means that \fBop\fR is a binary operator which takes operands of type
65 \fIinteger\fR and produces a result of type \fIboolean\fR.
66 The ``(3)'' means that the priority of \fBop\fR is 3.
67 Operands are automatically converted to the appropriate type. The type
68 \fIany\fR is used for operator that take operands of any type.
72 \fI\\$1\fB \\$2 \fI\\$3\fR \-> \\fI\\$4\\fR (\\np)
76 \\$1 \fI\\$2\fR \-> \\fI\\$3\\fR (\\np)
79 Returns the value of the left hand operand if the left hand operand
84 and the value of the right hand operand otherwise.
85 The right hand operand is evaluated only if necessary.
86 ``|'' is a synonym for ``\-o''.
89 Returns the value of the left hand operand if the left hand operand
94 and the value of the right hand operand otherwise.
95 The right hand operand is evaluated only if necessary.
96 ``&'' is a synonym for ``\-a''.
99 Returns true if the operand is false, and false if the operand is true.
101 .b string = string boolean
102 True if the two strings are equal.
103 .b string != string boolean
104 True if the two strings are not equal.
105 .b integer \-eq integer boolean
106 True if the two operands are equal.
107 .b integer \-ne integer boolean
108 True if the two operands are not equal.
109 .b integer \-gt integer boolean
110 True if the first operand is greater than the second one.
111 .b integer \-lt integer boolean
112 True if the first operand is less than the second one.
113 .b integer \-ge integer boolean
114 True if the first operand is greater than or equal to the second one.
115 .b integer \-le integer boolean
116 True if the first operand is less than or equal to the second one.
118 .b integer + integer integer
120 .b integer \- integer integer
121 Subtract two integers.
123 .b integer * integer integer
124 Multiply two integers. ``*'' is special to the shell, so you generally
125 have to write this operator as ``\e*''.
126 .b integer / integer integer
128 .b integer % integer integer
129 Returns the remainder when the first operand is divided by the second one.
131 .b string : string "integer or string"
132 The second operand is interpreted as a regular expression (as in the
136 This operator attempts to match part (or all) of the first operand
137 with the regular expression. The match must start at the beginning of
139 If the regular expression contains \e( \e) pairs, then the result
140 of this operator is the string which is matched by the regular expression
141 between these pairs, or the null string if no match occurred. Otherwise,
142 the result is the number of characters matched by the regular expression,
143 or zero if no no match occurred.
145 .u \-n string integer
146 Returns the number of characters in the string.
147 .u \-z string boolean
148 Returns true if the string contains zero characters.
149 .u \-t integer boolean
150 Returns true if the specified file descriptor is associated with a tty.
152 The remaining operators all deal with files. Except as noted, they return
154 specified file does not exist. The ones dealing with permission use
155 the effective user and group ids of the shell.
156 .u \-r string boolean
157 True if you have read permission on the file.
158 .u \-w string boolean
159 True if you have write permission on the file.
160 .u \-x string boolean
161 True if you have execute permission on the file.
162 .u \-f string boolean
163 True if the file is a regular file.
164 .u \-d string boolean
165 True if the file is a directory.
166 .u \-c string boolean
167 True if the file is a character special file.
168 .u \-b string boolean
169 True if the file is a block special file.
170 .u \-p string boolean
171 True if the file is a named pipe (i.e. a fifo).
172 .u \-u string boolean
173 True if the file is setuid.
174 .u \-g string boolean
175 True if the file is setgid.
176 .u \-k string boolean
177 True if the file has the sticky bit set.
178 .u \-s string "integer or boolean"
179 Returns the size of the file, or 0 if the file does not exist.
180 .u \-h string boolean
181 True if the file is a symlink. This is the only file test operator that
182 does not follow symlinks, all others do. So ``\-d'' and ``\-h''
183 are both true on a symlink pointing to a directory.
184 ``\-L'' is a synonym for ``\-h''.
190 if the result were converted to
197 if the result were converted to
202 is syntactically incorrect.
205 filesize=`expr \-s file`
206 Sets the shell variable
211 if [ \-s file ]; then command; fi
216 exists and is not empty.
218 x=`expr "$x" : '.\\{4\\}\\(.\\{0,3\\}\\)'`
223 beginning after the fourth character of
225 and continuing for three characters or until the end of the string,
226 whichever comes first.
228 x=`expr X"$x" : X'.\\{4\\}\\(.\\{0,3\\}\\)'`
229 This example is the same as the previous one, but it uses a leading
230 ``X'' to make things work when the value of
232 looks like an operator.
234 The relational operators of the System V
236 command are not implemented.
238 Certain features of this version of
240 are not present in System V, so care should be used when writing