shell编程之数值运算

Posted xyhero

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell编程之数值运算相关的知识,希望对你有一定的参考价值。

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


















以上是关于shell编程之数值运算的主要内容,如果未能解决你的问题,请参考以下文章

Shell编程Shell中Bash变量-数值运算运算符变量测试和内容替换

Shell编程 之 运算符

shell编程之运算符

shell编程之变量

Shell编程

shell编程之shell 运算