Arithmetic Expansion $(( ))
In this page:
Arithmetic Expansion $(( ))
$(( expression )) evaluates an integer arithmetic expression directly, without needing spaces around operators or an external command. It supports + - * / % and comparison/logical operators, all using normal integer math. This is the standard, modern way to do arithmetic in Bash.
Note: $(( )) only supports integers — there is no built-in floating-point arithmetic in Bash.
Example: Arithmetic Expansion $(( ))
#!/bin/bash
a=10
b=3
echo "Sum: $((a + b))"
echo "Product: $((a * b))"
echo "Integer division: $((a / b))"
echo "Remainder: $((a % b))"
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: