Purpose:Evaluate an expression and display the result on STDOUT


Format:EXPR string : regex        Regular expression match of regex against string
EXPR match string regex        Same as string : regex
EXPR substr string pos len        Substring of string, pos starts at 1
EXPR index string chars        Index in string (first character is 1) where anything in chars is found, or 0 if nothing matches
EXPR length string        Length of string
arg1 [operator] arg2...        This can be any arithmetic expression supported by @EVAL, or any conditional expression supported by IF  /IFF.


See also: Conditional expressions, IFF, @IF.




EXPR evaluates integer or string expressions, including pattern matching regular expressions. EXPR will expand variables on the command line before evaluating the expression, unless they are escaped or back quoted.


If you have special characters (i.e., < > & |) on the line you must either enclose the entire expression in double quotes (EXPR will remove them before evaluating the expression) or escape them.


The regular expression match is always anchored (i.e., there is an implied leading ^). If the regular expression contains (), and it matches at least part of stringEXPR returns that part of string; if there is no match, EXPR results in 0. If the regular expression doesn't contain (..), the result is the number of characters matched. MATCH performs the same operation as the colon operator.




expr text : tex



expr text : (.*)



expr 5 + 3 +1



expr length hello



expr index hello l



expr substr hello 2 3