bc—processes precision arithmetic

bc [ -lwsqv ] [long-options] [  file … ]

bc is an interactive processor for a language that resembles C but provides unlimited precision arithmetic. It takes input from any files given, then reads the standard input.

Example A.7.
1    bc << EOF
     4.5 + 5.6 / 3
     Output : 6.366
2    bc
     101 (Output)
     10100 (Output


  1. This is a here document. From the first EOF to the last EOF, input is given to the bc command. The scale specifies the number of digits to the right of the decimal point. The result of the calculation is displayed on the screen.

  2. The number base is two. The number is converted to binary (ATT only).

Get Linux Shells by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.