The expr command is a Unix/Linux utility used for evaluating expressions and performing basic arithmetic operations in the terminal. It can handle integer arithmetic, string operations, and logical comparisons.
Basic Usage:
- Arithmetic Operations: You can perform addition, subtraction, multiplication, and division.
- Syntax: The general syntax is:
expr <expression>
Examples:
-
Addition:
expr 5 + 3 # Outputs: 8 -
Subtraction:
expr 10 - 4 # Outputs: 6 -
Multiplication:
expr 6 \* 7 # Outputs: 42 (note the backslash before *) -
Division:
expr 20 / 4 # Outputs: 5
Important Notes:
- Ensure there are spaces around operators.
- For multiplication, use a backslash (
\) before the asterisk (*) to avoid shell interpretation.
If you have more questions about expr or need examples, let me know!
