45.28 Quick Reference: expr
Here's the syntax. The [brackets] mean "optional"; don't type the brackets:
Arguments and operators must be separated by spaces. In many cases, an argument is an integer, typed literally or represented by a shell variable. There are three types of operators: arithmetic, relational, and logical. Exit status ( 44.7 ) values for expr are 0 if the expression evaluates non-zero and non-null, 1 if the expression evaluates to 0 or null, or 2 if the expression is invalid.
45.28.1 ExamplesDivision happens first; output is 10:
$ Addition happens first; output is 7 (truncated from 7.5):
$ Add 1 to variable i ; this is how variables are incremented in Bourne shell scripts:
Output 1 (true) if variable a is the string "hello":
$ Output 1 (true) if variable b plus 5 equals 10 or more:
$ In the examples below, variable p is the string "version.100". This command returns the number of characters in p :
$ Match all characters and print them:
$ Output the number of lowercase letters matched:
$ Match a string of lowercase letters:
$
Truncate
$ - from O'Reilly & Associates' UNIX in a Nutshell (SVR4/Solaris) |
|