shell 基础4

数值运算:

declare:声明变量类型

declare [+/-][选项] 变量名
选项:
-:给变量设定类型属性
+:取消变量的类型属性
-i:将变量声明为整数型(integer)
-x:将变量声明为环境变量
-p:显示指定变量的被声明的类型

[root@localhost tmp]# aa=11
[root@localhost tmp]# bb=22
[root@localhost tmp]# cc=$aa+$bb
[root@localhost tmp]# echo $cc
11+22

方法一:
[root@localhost tmp]# declare -i cc=$aa+$bb
[root@localhost tmp]# echo $cc
33

方法二:
[root@localhost tmp]# aa=11
[root@localhost tmp]# bb=22
[root@localhost tmp]# dd=$(expr $aa + $bb)
[root@localhost tmp]# echo $dd
33
说明:+号两侧的空格不能省略

方法三:
[root@localhost tmp]# aa=11
[root@localhost tmp]# bb=22
[root@localhost tmp]# ee=$(($aa + $bb))
[root@localhost tmp]# echo $ee
33


[root@localhost tmp]#
[root@localhost tmp]# declare -p cc
declare -i cc="33"
[root@localhost tmp]# declare -p aa
declare -- aa="11"
[root@localhost tmp]# declare -p bb
declare -- bb="22"

 

转载于:https://www.cnblogs.com/javasl/p/11155131.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值