.\" SCCSID: @(#)expr.1 8.1 9/11/90 .\" SCCSID: @(#)expr.1 8.1 9/11/90 .TH expr 1 .SH Name expr \- evaluate expressions .SH Syntax .B expr \fIarg\fR... .SH Description .NXR "expr command" .NXR "expression" "taking arguments as" The arguments are taken as an expression. After evaluation, the result is written on the standard output. Each token of the expression is a separate argument. .PP The operators and keywords are listed below. The list is in order of increasing precedence, with equal precedence operators grouped. .TP 20 .IR expr " | " expr Yields the first .I expr if it is neither null nor 0. Otherwise yields the second .I expr. .TP .IR expr " & " expr Yields the first .I expr if neither .I expr is null or 0. Otherwise yields 0. .TP .I expr relop expr The .I relop is one of < = > and yields 1 if the indicated comparison is true, '0' if false. The comparison is numeric if both .I expr are integers, otherwise lexicographic. .TP .IR expr " + " expr .RS 5 .IR expr " - " expr .RE .RS 20 Yields addition or subtraction of the arguments. .RE .TP 20 .IR expr " * " expr .RS 5 .IR expr " / " expr .br .IR expr " % " expr .RE .RS 20 Yields multiplication, division, or remainder of the arguments. .RE .TP 20 .IR expr " : " expr The matching operator compares the string first argument with the regular expression second argument; regular expression syntax is the same as that of .MS ed 1 . The \fB\\(\|.\|.\|.\|\\)\fP pattern symbols can be used to select a portion of the first argument. Otherwise, the matching operator yields the number of characters matched ('0' on failure). .TP .RI ( " expr " ) parentheses for grouping. .SH Examples .NXR "expr command" "examples" The first example adds 1 to the Shell variable \fIa\fP\^: .EX a=\`expr $a + 1\` .EE The second example finds the file name part (least significant part) of the pathname stored in variable \fIa, .EX expr $a : \'.*/\e(\^.*\e)\' \'\^|\' $a .EE Note the quoted Shell metacharacters. .SH Diagnostics The .PN expr command returns the following exit codes: .IP 0 5 The expression is neither null nor '0'. .IP 1 The expression is null or '0'. .IP 2 The expression is invalid. .SH See Also ed(1), sh(1), test(1)