Forrest logo
back to the expr tool

expr:tldr:0561c

expr: Calculate a specific mathematic expression.
$ expr ${expression1} ${select} ${expression2}
try on your machine

The command "expr ${expression1} ${select} ${expression2}" is used to evaluate and calculate arithmetic expressions in the shell scripting language.

Here's how it works:

  • ${expression1} and ${expression2} are placeholders for the numeric expressions that you want to evaluate. These expressions can be variables, constants, or a combination of both.

  • ${select} is a placeholder for the operator that you want to use to perform the calculation. It can be +, -, *, /, or %. These operators represent addition, subtraction, multiplication, division, and modulo respectively.

When you run the command, the shell evaluates the values of ${expression1} and ${expression2} and performs the arithmetic operation specified by ${select}. It then returns the result of the calculation.

For example, if you run the command "expr 5 + 3", the shell will replace ${expression1} with 5, ${select} with +, and ${expression2} with 3. The expression becomes "expr 5 + 3", and the shell calculates the sum of 5 and 3, which is 8. The result is then returned by the command.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the expr tool