|
expr is a command line Unix utility which evaluates an expression and outputs the corresponding value. Screenshot of a sample Bash session, taken on Linux. ...
Wikibooks has more about this subject: Guide to UNIX Unix or UNIX is a computer operating system originally developed in the 1960s and 1970s by a group of AT&T Bell Labs employees including Ken Thompson, Dennis Ritchie, and Douglas McIlroy. ...
Expression may refer to: (in the vernacular) the act or particular way of expressing something (including an emotion through a facial expression or configuration) (in mathematics) a mathematical expression (in computing) a programming language expression (in computing) a vector graphics software Microsoft Expression (in genetics) the effect produced by a...
Syntax: expr (expression) expr evaluates integer or string expressions, including pattern matching regular expressions. Most of the challenge posed in writing expressions is preventing the command line shell from acting on characters intended for expr to process. A regular expression (abbreviated as regexp, regex, or regxp, with plural forms regexps, regexes, or regexen) is a string that describes or matches a set of strings, according to certain syntax rules. ...
The operators available - for integers: addition, subtraction, multiplication, division and modulus
- for strings: find substring, find regular expression, find a set of characters in a string, length of string
- for either: comparison (equal, not equal, less than, etc.)
Also, boolean expressions involving and and or, such as expr length "abcdef" < 5 "|" 15 - 4 ">" 8 outputs "1". This is because length "abcdef" is 6, which is not less than (the backslash escapes a less than from the shell) 5 (so the left side of the | returns zero). But 15 minus 4 is 11 and is greater than 8, so the right side is true, which makes the or true, so 1 is the result. (The return value—the program exit status—is zero for this example.)
External links
|