Do quick, accurate arithmetic directly in the terminal with the bc calculator. 16.11.2025 | reading time: 2 min Need a quick calculator without leaving the shell? Use bc, the arbitrary-precision calculator shipped on most Linux systems, to perform arithmetic, apply functions and embed math in scripts right from the terminal. Real invoice calculation Show, don’t tell: compute a price with VAT directly in the shell and observe scale behavior. ``` $ echo "scale=2; 1234.56*1.075" | bc -l 1327.15 ``` Here `-l` loads the math library and sets a high default precision; setting `scale=2` truncates to two decimals, which is visible in the output. Exact math and interactive work Run bc interactively for exploratory work or pass expressions from scripts; define variables and functions, and control decimal places with `scale`; example interactive start: `bc -l` then type `2^10`, press Enter and get `1024` immediately; bc uses arbitrary precision but truncates when `scale` limits digits. Practical tips and caveats Prefer `-l` for math functions like `s()` and `l()` and for a generous default `scale`; remember bc truncates rather than rounds when `scale` is set, so add a rounding offset if needed; embed bc in shells with here-strings or pipes, e.g. `result=$(echo "scale=4; (a*b)/c" | bc -l)` for scriptable arithmetic. Other tools that complement bc Use `dc` for reverse-polish calculations, `awk` when processing columns with inline math, and `python3` for complex numeric logic or reliable rounding; choose the tool that fits the task size and readability of the script. Next steps for mastery Try converting real log data, calculating ratios across files, and writing a small billing helper that formats totals with `printf` after bc does the math; deepen Linux skills and consider exam paths such as CompTIA Linux+ or LPIC-1 with intensive preparation at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting troubleshooting