shell编程之数值运算

declare -r 变量名=变量1+变量2
[root@192 test]# aa=11
[root@192 test]# bb=22
[root@192 test]# declare -i cc=$aa+$bb
[root@192 test]# echo $cc
33
[root@192 test]# dd=$(expr $aa + $bb) 注意:expr后面的加号前后有空格
[root@192 test]# echo $dd
33
[root@192 test]# ee=$(($aa+$bb)) 推荐使用
[root@192 test]# echo $ee
33
[root@192 test]# gg=$[$aa+$bb]
[root@192 test]# echo $gg
33
[root@192 test]# aa=$(((11+3)*2-1)) 小括号优先级高
[root@192 test]# echo $aa
27

猜你喜欢

转载自www.cnblogs.com/xyhero/p/9343698.html