Session and utilities

The bc command

Arbitrary-precision calculator. Unlike the shell, it handles decimals without losing precision.

Syntax

echo 'expresión' | bc

Most useful options

-lLoads the math library (decimals and functions)

Copy-ready examples

$ echo '2+2' | bcSimple addition
$ echo '1/3' | bc -lDivision with decimals

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Without -l, bc works with integers and 1/3 gives 0.

Related commands

FAQ

How do I get many decimals?

With scale: echo 'scale=4; 1/3' | bc.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course