Bash Math Math using bc


Example

bc is an arbitrary precision calculator language. It could be used interactively or be executed from command line.

For example, it can print out the result of an expression:

echo '2 + 3' | bc
5

echo '12 / 5' | bc
2

For floating-post arithmetic, you can import standard library bc -l:

echo '12 / 5' | bc -l
2.40000000000000000000

It can be used for comparing expressions:

echo '8 > 5' | bc
1

echo '10 == 11' | bc
0

echo '10 == 10 && 8 > 3' | bc
1