Expansion and Data
Arithmetic
Updating Counters
Bash arithmetic is integer arithmetic. It is useful for counters, totals, and small control decisions.
Program
Play the script to watch count change, then feed a second calculation.
arithmetic.sh
#!/usr/bin/env bash
count=7
count=$((count + 5))
half=$((count / 2))
echo "$count:$half"
integer arithmetic
Bash arithmetic drops fractional parts because it works with integers.
counter update
A variable can be read and assigned again in the same arithmetic expression.