AnyCompiler

Arithmetic

$(( expression )) evaluates expression as arithmetic rather than as a string, with the usual operators. Unlike every numeric type anywhere else on this site, Bash arithmetic is strictly integer-only — there is no floating-point math at all, so 7 / 2 truncates to 3, not 3.5.

echo $((7 / 2))
echo $((7 % 2))
echo $((2 ** 10))
Output
3
1
1024

What the real error looks like

Dividing by zero inside $(( )) isn't a quiet result like infinity — it's a fatal error that stops the script immediately, unlike the forgiving command-not-found case from the variables lesson. This is genuinely what the real run reports — captured from a real execution, not written to look plausible:

echo $((10 / 0))
Output
script.sh: line 1: 10 / 0: division by 0 (error token is "0")

Next: command substitution and pipes — chaining commands together, and capturing a pipeline's result.

Practice exercise

Print the result of (6 + 4) * 3, then print the remainder of 17 % 5, both using $(( )) arithmetic.