1c9fe00dcSJ.T. Conklin.\" Copyright (c) 1993 Winning Strategies, Inc. 2c9fe00dcSJ.T. Conklin.\" All rights reserved. 3c9fe00dcSJ.T. Conklin.\" 4c9fe00dcSJ.T. Conklin.\" Redistribution and use in source and binary forms, with or without 5c9fe00dcSJ.T. Conklin.\" modification, are permitted provided that the following conditions 6c9fe00dcSJ.T. Conklin.\" are met: 7c9fe00dcSJ.T. Conklin.\" 1. Redistributions of source code must retain the above copyright 8c9fe00dcSJ.T. Conklin.\" notice, this list of conditions and the following disclaimer. 9c9fe00dcSJ.T. Conklin.\" 2. Redistributions in binary form must reproduce the above copyright 10c9fe00dcSJ.T. Conklin.\" notice, this list of conditions and the following disclaimer in the 11c9fe00dcSJ.T. Conklin.\" documentation and/or other materials provided with the distribution. 12c9fe00dcSJ.T. Conklin.\" 3. All advertising materials mentioning features or use of this software 13c9fe00dcSJ.T. Conklin.\" must display the following acknowledgement: 14c9fe00dcSJ.T. Conklin.\" This product includes software developed by Winning Strategies, Inc. 15c9fe00dcSJ.T. Conklin.\" 4. The name of the author may not be used to endorse or promote products 16c9fe00dcSJ.T. Conklin.\" derived from this software withough specific prior written permission 17c9fe00dcSJ.T. Conklin.\" 18c9fe00dcSJ.T. Conklin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19c9fe00dcSJ.T. Conklin.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20c9fe00dcSJ.T. Conklin.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21c9fe00dcSJ.T. Conklin.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22c9fe00dcSJ.T. Conklin.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23c9fe00dcSJ.T. Conklin.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24c9fe00dcSJ.T. Conklin.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25c9fe00dcSJ.T. Conklin.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26c9fe00dcSJ.T. Conklin.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27c9fe00dcSJ.T. Conklin.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28c9fe00dcSJ.T. Conklin.\" 29c9fe00dcSJ.T. Conklin.\" $Header: /b/source/CVS/src/bin/expr/expr.1,v 1.1 1993/07/20 20:16:26 jtc Exp $ 30c9fe00dcSJ.T. Conklin.\" 31c9fe00dcSJ.T. Conklin.Dd July 3, 1993 32c9fe00dcSJ.T. Conklin.Dt EXPR 1 33c9fe00dcSJ.T. Conklin.Os 34c9fe00dcSJ.T. Conklin.Sh NAME 35c9fe00dcSJ.T. Conklin.Nm expr 36c9fe00dcSJ.T. Conklin.Nd evaluate expression 37c9fe00dcSJ.T. Conklin.Sh SYNOPSIS 38c9fe00dcSJ.T. Conklin.Nm expr 39c9fe00dcSJ.T. Conklin.Ar expression 40c9fe00dcSJ.T. Conklin.Sh DESCRIPTION 41c9fe00dcSJ.T. ConklinThe 42c9fe00dcSJ.T. Conklin.Nm expr 43c9fe00dcSJ.T. Conklinutility evaluates 44c9fe00dcSJ.T. Conklin.Ar expression 45c9fe00dcSJ.T. Conklinand writes the result on standard output. 46c9fe00dcSJ.T. Conklin.Pp 47c9fe00dcSJ.T. ConklinAll operators are separate arguments to the 48c9fe00dcSJ.T. Conklin.Nm expr 49c9fe00dcSJ.T. Conklinutility. 50c9fe00dcSJ.T. ConklinCharacters special to the command interpreter must be escaped. 51c9fe00dcSJ.T. Conklin.Pp 52c9fe00dcSJ.T. ConklinOperators are listed below in order of increasing precidence. 53c9fe00dcSJ.T. ConklinOperators with equal precidence are grouped within { } symbols. 54c9fe00dcSJ.T. Conklin.Bl -tag -width indent 55c9fe00dcSJ.T. Conklin.It Ar expr1 Li | Ar expr2 56c9fe00dcSJ.T. ConklinReturns the evaluation of 57c9fe00dcSJ.T. Conklin.Ar expr1 58c9fe00dcSJ.T. Conklinif it is neither an empty string nor zero; 59c9fe00dcSJ.T. Conklinotherwise, returns the evaluation of 60c9fe00dcSJ.T. Conklin.Ar expr2 . 61c9fe00dcSJ.T. Conklin.It Ar expr1 Li & Ar expr2 62c9fe00dcSJ.T. ConklinReturns the evaluation of 63c9fe00dcSJ.T. Conklin.Ar expr1 64c9fe00dcSJ.T. Conklinif neither expression evaluates to an empty string or zero; 65c9fe00dcSJ.T. Conklinotherwise, returns zero. 66c9fe00dcSJ.T. Conklin.It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2 67c9fe00dcSJ.T. ConklinReturns the results of integer comparision if both arguments are integers; 68c9fe00dcSJ.T. Conklinotherwise, returns the results of lexical comparison. 69c9fe00dcSJ.T. ConklinThe result of each comparison is 1 if the specified relation is true, 70c9fe00dcSJ.T. Conklinor 0 if the relation is false. 71c9fe00dcSJ.T. Conklin.It Ar expr1 Li "{+, -}" Ar expr2 72c9fe00dcSJ.T. ConklinReturns the results of addition or subtraction of integer-valued arguments. 73c9fe00dcSJ.T. Conklin.It Ar expr1 Li "{*, /, %}" Ar expr2 74c9fe00dcSJ.T. ConklinReturns the results of multiplication, integer division, or remainder of integer-valued arguments. 75c9fe00dcSJ.T. Conklin.It Ar expr1 Li : Ar expr2 76c9fe00dcSJ.T. ConklinThe 77c9fe00dcSJ.T. Conklin.Dq \: 78c9fe00dcSJ.T. Conklinoperator matches 79c9fe00dcSJ.T. Conklin.Ar expr1 80c9fe00dcSJ.T. Conklinagainst 81c9fe00dcSJ.T. Conklin.Ar expr2 , 82c9fe00dcSJ.T. Conklinwhich must be a regular expression. The regular expression is anchored 83c9fe00dcSJ.T. Conklinto the begining of the string with an invisible 84c9fe00dcSJ.T. Conklin.Dq ^ , 85c9fe00dcSJ.T. Conklintherefore 86c9fe00dcSJ.T. Conklin.Dq ^ 87c9fe00dcSJ.T. Conklinis not a special character. 88c9fe00dcSJ.T. Conklin.Pp 89c9fe00dcSJ.T. ConklinIf the pattern contains at lest one regular expression 90c9fe00dcSJ.T. Conklinsubexpression 91c9fe00dcSJ.T. Conklin.Dq "\e(...\e)" , 92c9fe00dcSJ.T. Conklinthe string corresponding to 93c9fe00dcSJ.T. Conklin.Dq "\e1" 94c9fe00dcSJ.T. Conklinis returned; 95c9fe00dcSJ.T. Conklinotherwise the matching operator returns the number of characters matched. 96c9fe00dcSJ.T. Conklin.El 97c9fe00dcSJ.T. Conklin.Pp 98c9fe00dcSJ.T. ConklinParentheses are used for grouping in the usual manner. 99c9fe00dcSJ.T. Conklin.Sh EXAMPLES 100c9fe00dcSJ.T. Conklin.Bl -enum 101c9fe00dcSJ.T. Conklin.It 102c9fe00dcSJ.T. ConklinThe following example adds one to the variable a. 103c9fe00dcSJ.T. Conklin.Dl a=`expr $a + 1` 104c9fe00dcSJ.T. Conklin.It 105c9fe00dcSJ.T. ConklinThe following example returns the filename portion of a pathname stored 106c9fe00dcSJ.T. Conklinin variable a. The // characters act to eliminate ambiguity with the 107c9fe00dcSJ.T. Conklindivision operator. 108c9fe00dcSJ.T. Conklin.Dl expr "//$a" Li : '.*/\e(.*\e)' 109c9fe00dcSJ.T. Conklin.It 110c9fe00dcSJ.T. ConklinThe following example returns the number of characters in variable a. 111c9fe00dcSJ.T. Conklin.Dl expr $a Li : '.*' 112c9fe00dcSJ.T. Conklin.El 113c9fe00dcSJ.T. Conklin.Sh DIAGNOSTICS 114c9fe00dcSJ.T. ConklinThe 115c9fe00dcSJ.T. Conklin.Nm expr 116c9fe00dcSJ.T. Conklinutility exits with one of the following values: 117c9fe00dcSJ.T. Conklin.Bl -tag -width Ds 118c9fe00dcSJ.T. Conklin.It 0 119c9fe00dcSJ.T. Conklinthe expression is neither an empty string nor 0. 120c9fe00dcSJ.T. Conklin.It 1 121c9fe00dcSJ.T. Conklinthe expression is an empty string or 0. 122c9fe00dcSJ.T. Conklin.It 2 123c9fe00dcSJ.T. Conklinthe expression is invalid. 124c9fe00dcSJ.T. Conklin.El 125c9fe00dcSJ.T. Conklin.Sh STANDARDS 126c9fe00dcSJ.T. ConklinThe 127c9fe00dcSJ.T. Conklin.Nm expr 128c9fe00dcSJ.T. Conklinutility 129c9fe00dcSJ.T. Conklinis expected to be 130c9fe00dcSJ.T. Conklin.St -p1003.2 131c9fe00dcSJ.T. Conklincompatible. 132