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
原文地址:https://www.cnblogs.com/xyhero/p/9343698.html
时间: 2024-11-13 09:50:49