bc calculated using floating shell

Copyright notice: reproduced please indicate the source. https://blog.csdn.net/u010720408/article/details/91395510

bash shell variables only supports character and integer, floating-point operations you want to perform, you need to use bc;

bc I understand the C language implementation of the bash shell;

var1=20
var2=3.14159
var3=`echo "scale=5;$var1 ^ 2 " | bc` #计算半径的平方
var4=`echo "scal3=6;$var3 * $var2" | bc` #计算圆的面积

Bc calculating a scale which is set to a decimal precision how many bits, the default is 0;
use of the pipeline will be calculated as convenient, or traditional values is also a nuisance

Guess you like

Origin blog.csdn.net/u010720408/article/details/91395510