expr
In this page:
expr
expr is an older external command that evaluates a simple arithmetic or string expression and prints the result. It requires spaces around every operator and operand, unlike $(( )). Most modern scripts prefer $(( )) or let, but expr still appears in older scripts.
Warning: expr 1+1 (no spaces) prints 1+1 literally instead of 2 — spaces around operators are mandatory.
Example: expr
#!/bin/bash
result=$(expr 5 + 3)
echo "5 + 3 = $result"
result=$(expr 10 \* 2)
echo "10 * 2 = $result"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: