方法一: declare命令
[root@localhost ~]# aa=22
[root@localhost ~]# bb=33
[root@localhost ~]# declare -i cc=$aa+$bb
方法二:用expr或let数值运算工具
[root@localhost ~]# aa=11
[root@localhost ~]# bb=99
[root@localhost ~]# dd=$(expr $aa + $bb) #dd的值是aa和bb的和。注意”+“号左右两侧必须有空格
方法三:"$((运算式))" 或 "$[运算式]"
[root@localhost ~]# aa=11
[root@localhost ~]# bb=99
[root@localhost ~]# ff=$(($aa+$bb))
[root@localhost ~]# gg=$[$aa+$bb]
928

被折叠的 条评论
为什么被折叠?



