Walid-Shouman
6/11/2017 - 11:03 AM

Tips for using bc calculator on bash

Tips for using bc calculator on bash

Execution

  • Command is bc
  • To have float answers, ie: 1/100 we need to execute with mathlib using bc -l
  • Most users don't execute the app directly, but rather pipe the expression string into bc, ie: echo "300/7" | bc -l.
  • We can control the precision with the use of scale Environment variable and removal of the numbers before the . similar to this answer.

Recall previous operation

  • Within bc, we may use the . special character to capture the previous value
1+5
.-2

The answer is 4.

References