expr Linux Commands
What is Linux expr Command?
Explanation
expr COMMAND
expr command evaluate the given expression and prints the value of expression to standard output.
SYNTAX
The Syntax is
expr expression
OPTIONS
--help |
display this help and exit. |
--version |
output version information and exit. |
Expressions :
ARG1 + ARG2 |
Evaluate the sum of ARG1 and ARG2 |
ARG1 - ARG2 |
Evaluate the difference of ARG1 and ARG2 |
ARG1 * ARG2 |
Evaluate the product of ARG1 and ARG2 |
ARG1 / ARG2 |
Evaluate the quotient of ARG1 divided by ARG2 |
STRING : REGEXP |
Pattern match of REGEXP in STRING |
match STRING REGEXP |
Same as STRING : REGEXP |
Example
-
expr 5 * 10
Output:
50
In the above example, the given two numbers are multiplied and the result is printed as output.
-
expr hscripts : hsc
Output:
3
In the above example, the command prints the number of characters which matches with the word 'hscripts'.