back toc next

Tests

expr

expr expression
Expr returns 0 if expression is neither null or 0, 1 if the expression is null or 0, and 2 for an invalid expression.

Examples

test if ARG1 is less than ARG2
expr 7 \< 3

add 1 to a number (and write the result to stdout)
expr $number + 1

match a substring
expr match "hello world" '.*ello wo'
returns 8
expr match "hello world" 'ello wo'
returns 0

index where a substring is found, else 0
expr index "this is an example" e
returns 12