Run high-precision math and small scripts directly in the shell with a tiny, powerful calculator. 22.02.2026 | reading time: 2 min Want exact math without leaving the shell? `bc` is a lightweight, arbitrary-precision calculator and scripting language you can run interactively or in pipelines to perform precise divisions, base conversions and small arithmetic programs. Quick Calculation Try this: calculate 12 divided by 7 with 20 decimal places and then run a small factorial function; the first example uses the math library, the second shows a here-doc script. ```bash echo "scale=20; 12/7" | bc -l ``` Output: ```text 1.71428571428571428571 ``` Factorial example: ```bash bc -l <<'BC' define fact(n) { if (n <= 1) return 1; return n * fact(n - 1); } fact(5) BC ``` Output: ```text 120 ``` Beyond the Basics Set precision with `scale`, enable common math functions with `-l`, define variables and functions, and embed bc in shell scripts; `ibase` and `obase` handle base conversion but must be used carefully because changing bases can affect subsequent assignments, so test interactively first. Complementary Tools Use `dc` for stack-based reverse-polish calculations and backward-compatibility scripts, `awk` when you need field-aware arithmetic in text processing, and `python3` for complex numeric libraries or when performance and readability matter more than tiny dependencies. Final Note Mastering `bc` gives you a reliable, scriptable way to do precise math from the shell; experiment with interactive mode, pipe it into tools, and combine it with shell logic to automate calculations — then consider deepening your Linux skills and certification preparation at bitsandbytes.academy for CompTIA Linux+ or LPIC-1 training. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting troubleshooting