Simple Arithmetic with bc

Sometimes you may wish to compute simple arithmetic on the terminal without launching a programming language. This is in-fact often useful when performing data wrangling on logs or text files. The terminal has a useful program bc that performs simple arithmetic on the terminal.

In the example below, we compute some simple arithmetic expressions: 21 + 3 - (10 * 9)

$ echo "21 + 3 - (10 * 9)" | bc
-66

Use the scale parameter to determine precision of arithmetic output

$ echo "scale=3; (2*3)/36" | bc
.166

Interaction between ints and floats will return floats

$ echo "21 - 2.7" | bc
18.3