← Back to Bash Course | Chapter 4: Loops | Lesson 3 of 14

Arithmetic Expansion $(( ))

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 $(( ))

bash
#!/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 run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.