In the command line, sometimes a simple manual mathematical computation is required. The built-in "BC" command is the front end of an "arbitrary precision computing language". If you are a person who is working and learning mathematics, it is very meaningful to check how it works in man. Therefore, you can perform some daily computing work on the command line.
Use BC, enter "BC" in the command prompt, and then use "+", "-", "*" (multiplication), and "/" (Division). For example, if the calculation result is 200 multiplied by 133, enter "200*133" and press Enter.
By default, the BC calculation result has no decimal places. You can enter "scale = 8", so that the calculation result will be accurate to 8 digits after the decimal place.
After the calculation is complete, press Ctrl + D to exit.
The BC switching mode may be cumbersome for simple computation, so you can create a shell script to directly perform computation.
Open gedit and enter the following content:
#! /Bin/bash
# Run input through BC for simple math purposes
Scale = 'scale = 8; '# No of decimal places for result
Math =$ {scale }$ @
Echo $ math | BC
Keep exiting. Change the File Permission to "executable" and copy it to the "/usr/bin" directory.
$ Chmod + x calc
$ Sudo MV calc/usr/bin/
Now this command can be directly executed, for example, input:
$ Calc 203 + 99/16
After the execution is completed, the result "209.1875" is output ".
In addition, you can also use echo "1 + 1" | BC-l command