shell 算数运算
expr:
[root@xiaoyuan ~]# expr 2+4 # 需要空格
2+4
[root@xiaoyuan ~]# expr 2 + 4
6
[root@xiaoyuan ~]# expr 2 * 4 # *需要转义,不然报错
expr: syntax error
[root@xiaoyuan ~]# expr 2 \* 4
8
[root@xiaoyuan ~]# sum=`expr 3 + 4`
[root@xiaoyuan ~]# echo $sum
7
[root@xiaoyuan ~]#
bc:
[root@xiaoyuan ~]# echo 3*5 | bc
15
[root@xiaoyuan ~]# echo 3/5 | bc
0
[root@xiaoyuan ~]# echo 3/5 | bc -l
.60000000000000000000
$(())
[root@xiaoyuan ~]# sum=$((3+4))
[root@xiaoyuan ~]# echo $sum
7
[root@xiaoyuan ~]# sum=$((3*4))
[root@xiaoyuan ~]# echo $sum
12
[root@xiaoyuan ~]# sum=$((3/4))
[root@xiaoyuan ~]# echo $sum
0
[root@xiaoyuan ~]# sum=$((4/3))
[root@xiaoyuan ~]# echo $sum
1
$[ ]
[root@xiaoyuan ~]# echo $sum
7
[root@xiaoyuan ~]# sum=$[3*4]
[root@xiaoyuan ~]# echo $sum
12
[root@xiaoyuan ~]# sum=$[3+4]
[root@xiaoyuan ~]# echo $sum
7
[root@xiaoyuan ~]# sum=$[3/4]
[root@xiaoyuan ~]# echo $sum
0
[root@xiaoyuan ~]# sum=$[3-4]
[root@xiaoyuan ~]# echo $sum
-1
posted on 2020-04-24 23:43 __director 阅读(76) 评论(0) 编辑 收藏 举报