实战演练
- 普通算数
[root@shaofeng ~]# no1=4
[root@shaofeng ~]# no2=5
[root@shaofeng ~]# let no1+=5
[root@shaofeng ~]# echo $no1
9
[root@shaofeng ~]# result=$[ no1 + no2 ]
[root@shaofeng ~]# echo $result
14
bc
- 计算平方以及平方根
[root@shaofeng ~]# echo "sqrt(100)" | bc 10
- 设定小数精度
[root@shaofeng ~]# echo "scale=2;8/3" | bc 2.66
- 进制转换
[root@shaofeng ~]# no=100 [root@shaofeng ~]# echo "obase=2;$no" |bc 1100100 [root@shaofeng ~]# no=1100100 [root@shaofeng ~]# echo "obase=10;ibase=2;$no" | bc 100