Ad space (banner)
🖥️Linux Lessons
Lesson 52 / 61

Doing Simple Math with expr

expr is for when "I want to do a quick calculation right in the terminal." expr stands for expression, and it evaluates a given expression or string operation and prints the result.

Use it in the form expr number1 operator number2. Operators like + - * / are supported, but each element needs to be separated by a space.

Running expr 3 + 4 prints 7, the result of adding 3 and 4.

A common early mistake is forgetting the spaces between the numbers and operator, writing 3+4 instead, which doesn't calculate correctly. expr requires each element to be separated by a space.

In real work, this is used for lightweight numeric processing inside shell scripts — counting files, computing a simple loop count, and so on (complex calculations use awk or bc instead).

Linux
Try it (type this into the pseudo terminal)
expr 3 + 4

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)