The bc command is a calculator language that supports arbitrary precision interactive execution. Bash has built-in support for four arithmetic operations on integers, but it does not support floating-point operations. The bc command can easily perform floating-point operations. Of course, integer operations are no longer a problem.
grammar
bc(options)(parameters)
Options
-i: Force into interactive mode;
-l: defines the standard math library used;
- w : warn about POSIX bc extensions;
-q: do not print normal GNU bc environment information;
-v: Display command version information;
-h: Display help information for the command.
parameter
File: Specify the file that contains the calculation task.
example
Arithmetic operations advanced operations bc command It can perform floating point operations and some advanced functions:
echo "1.212*3" | bc
3.636
Set decimal precision (value range)
echo "scale=2;3/8" | bc 0.37