首页 > 其他 > 详细

数据运算,条件测试,if选择结构

时间:2018-02-11 22:34:22      阅读:268      评论:0      收藏:0      [点我收藏+]
Shell中的数值运算
1、整数运算工具
一。使用expr工具
Last login: Sun Feb 11 21:08:31 on console
Thegod:~ chengde$ x=1234 //定义变量x
Thegod:~ chengde$ expr $x + 78 //加法
1312
Thegod:~ chengde$ expr $x - 78 //减法
1156
Thegod:~ chengde$ expr $x * 78 //乘法,操作符应添加\转义
96252
Thegod:~ chengde$ expr $x / 78 //除法,仅保留整除结果
15
Thegod:~ chengde$ expr $x % 78 //求模
64

二。使用$[ ]或$(())表达式

[root@pangdanet ~]# x=1234
[root@pangdanet ~]# echo $[x+78]
1312
[root@pangdanet ~]# echo $[x-78]
1156
[root@pangdanet ~]# echo $[x*78]
96252
[root@pangdanet ~]# echo $[x/78]
15
[root@pangdanet ~]# echo $[x%78]
64

三。使用let命令

[root@2015idc ~]# x=1234
[root@2015idc ~]# let y=x+22
[root@2015idc ~]# echo $y
1256
[root@2015idc ~]# let x+=78;echo $x # x+=78(x=x+78)
1312
[root@2015idc ~]# let x-=78;echo $x # x-=78(x=x-78)
1234
[root@2015idc ~]# let x=78;echo $x # x=78(x=x*78)
96252
[root@2015idc ~]# let x/=78;echo $x # x/=78(x=x/78)
1234
[root@2015idc ~]# let x%=78; echo $x # x%=78(x=x%79)
64

未完,待续

数据运算,条件测试,if选择结构

原文:http://blog.51cto.com/20214843/2071215

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!