Unix bc Command Line Calculator in Batch Mode

You may be using bc command in command line for calculations. It can also be used for batch mode calculations as explained below.

1. Calculation using Single command

$ echo "4+10" | bc
14

2. Calculation using Multiple commands

$ echo "obase=15;5+9" | bc
E

3. Using previous results in the current operation

In the following example, “last” represents the result of the previous calculation.

echo "1+3;last/2" | bc
4
2

In the following example, . (dot) represents the result of the previous calculation.

$ echo "1+3;./2" | bc
4
2

4. Another way of executing bc calculation

bc <<< 4+2
6

Comments

Popular posts from this blog

How to delete SEA in VIOS

More VIOS commands

Webmin configuration for LDAP