Windows set /a (arithmetic) equivalent in Linux
Evaluates mathematical expressions in scripts or at the command line.
set /a (arithmetic)
$(( expression ))
$(( expression ))
$(( expression ))
Overview
What this command does
On Windows, "set /a (arithmetic)" is used to perform arithmetic calculations. On Linux, the closest practical mapping shown here is "$(( expression ))". Evaluates mathematical expressions in scripts or at the command line. This reference is grouped under Terminal & Shell Scripting → Terminal.
Windows → Linux context
What changes when you use this on Linux?
Equivalent task, different tool
Windows set /a (arithmetic) maps to $(( expression )) for this task. Treat this as a workflow mapping rather than a character-for-character syntax translation.
Portable across the compared distros
The Debian/Ubuntu, Fedora and Arch rows use the same command in this mapping. Package availability or defaults can still vary, so check the installed tool version when an option behaves differently.
For the broader concept behind this mapping, read Linux command-line basics.
Practical tasks
Common use cases
Perform arithmetic calculations
Evaluates mathematical expressions in scripts or at the command line.
echo $((5 + 3))
Simple arithmetic
echo $((2 ** 10))
Power: 2^10 = 1024
echo $((100 / 3))
Integer division
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
echo $((5 + 3))
echo $((10 * 7))
echo $((2 ** 8))
echo 'scale=2; 10/3' | bc
Walkthrough
Examples with explanations
# Windows: set /a result = 5 + 3
echo $((5 + 3)) # 8
echo $((10 * 7)) # 70
echo $((2 ** 8)) # 256
# Floating point:
echo 'scale=2; 10/3' | bc # 3.33
Reference
Common options and variations
| Command or option | Use |
|---|---|
echo $((5 + 3)) | Simple arithmetic |
echo $((2 ** 10)) | Power: 2^10 = 1024 |
echo $((100 / 3)) | Integer division |
echo 'scale=4; 22/7' | bc | Float with 4 decimal places |
python3 -c 'print(22/7)' | Float via Python |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
Debian/Ubuntu, Fedora and Arch all use "$(( expression ))" for this mapping. The command syntax shown here is portable across the three rows, although installed versions and system defaults can still vary.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | same command | $(( expression )) |
Same command on this distribution. |
| Fedora | same command | $(( expression )) |
Same command on this distribution. |
| Arch | same command | $(( expression )) |
Same command on this distribution. |
Keep learning