bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty‘.
3.1415*3*3
28.2735
r=3
3.1415*r*r
28.2735
13/(3+4)
1
13.0/(3+4)
1
13.0/(3.0+4.0)
1
bc -q #-q选项使得bc运算器不输出版本信息
13/(3+4) #未设置scale之前,除法运算结果自动取整
1
scale=4 #将scale改为4
13/(3+4)
1.8571 #除法结果小数点后保留4位小数
quit
在脚本中使用bc运算器的例子
variable=`echo "options;expression" | bc`
vi calare.sh
#!/bin/bash
var1=20
var2=3.14159
var3=`echo "scale=5; $var1 ^ 2" | bc` #计算半径的平方
var4=`echo "scale=5; $var3 * $var2" | bc` #计算圆的面积
echo "The area of this circle is: $var4"
./calare.sh
The area of this circle is: 1256.63600