linux中常用的数值计算

 

001、 expr

[root@localhost test]# expr 3 + 5
8
[root@localhost test]# expr 3 - 5
-2
[root@localhost test]# expr 3 * 5
15
[root@localhost test]# expr 3 / 5      ## 支持加减乘除
0
[root@localhost test]# expr 3 / 5.3    ## 不支持浮点运算
expr: non-integer argument
[root@localhost test]# expr 5 / 3
1
[root@localhost test]# expr 8 / 3      ## 直接截断
2

image

 

002、echo + bc

[root@localhost test]# echo "5 + 3" | bc
8
[root@localhost test]# echo "5 - 3" | bc
2
[root@localhost test]# echo "5 * 3" | bc
15
[root@localhost test]# echo "5 / 3" | bc
1
[root@localhost test]# echo "scale = 3; 5 / 3" | bc          ## 支持浮点运算
1.666
[root@localhost test]# echo "scale = 5; 5 / 3" | bc
1.66666

image

 

 

posted @ 2025-07-28 21:51  小鲨鱼2018  阅读(8)  评论(0)    收藏  举报