expr
| expr | |
|---|---|
Example of expr command that does basic summation | |
| Original authors | Dick Haight (AT&T Bell Laboratories) |
| Developers | Various open-source and commercial developers |
| Initial release | 1979 |
| Operating system | Unix, Unix-like, IBM i |
| Platform | Cross-platform |
| Type | Command |
expr is a shell command that evaluates an expression and outputs the result. It evaluates integer or string expressions, including pattern matching regular expressions. Comparison operators (equal, not equal, less than, etc.) apply to both integer and string values. Integer-specific operations include addition, subtraction, multiplication, division and modulus. String-specific operators include:
- matching a regular expression (
match, or the colon syntax "str" : "reg" for an arbitrary string "str" and regular expression "reg") - finding a set of characters in a string (
index) - finding a substring (
substr) - finding the length of a string (
length)
Each symbol (operator, value, etc.) in the expression must be given as a separate parameter. A common challenge with using the command is preventing the shell from acting on input indented to be the expression as something other than expression.
Originally developed for Unix v7 and standardized by POSIX, the command is available on IBM i, and for Windows via UnxUtils.