数据运算,条件测试,if选择结构
Shell中的數(shù)值運算
1、整數(shù)運算工具
一。使用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 //乘法,操作符應(yīng)添加\轉(zhuǎn)義
96252
Thegod:~ chengde$ expr $x / 78 //除法,僅保留整除結(jié)果
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
未完,待續(xù)
轉(zhuǎn)載于:https://blog.51cto.com/20214843/2071215
總結(jié)
以上是生活随笔為你收集整理的数据运算,条件测试,if选择结构的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 框架之---Django
- 下一篇: 基础005_V7-Select IO