shell-变量的数值运算let内置命令
1. let命令的用法
格式:
let 赋值表达式
【注】let赋值表达式功能等同于:((赋值表达式))
范例1:给自变量i加8
[ scripts]# i=2 [ scripts]# let i=i+8 [ scripts]# echo $i 10 [ scripts]# i=i+8 #去掉let定义 [ scripts]# echo $i i+8 输出的结果 提示:let i=i+8等同于((i=i+8)),但后者效率更高
范例2:利用let计数监控web服务状态
#监控服务状态 #!/bin/bash CheckUrl(){ #服务状态监控 timeout=5 fails=0 success=0 while true do wget --timeout=$timeout --tries=1 http://www.baid1u.com -q -O /dev/null if [ $? -ne 0 ] then let fails=fails+1 else let success+=1 fi if [ $success -ge 1 ];then echo success exit 0 fi if [ $fails -ge 2 ];then echo fail exit 2 fi done } CheckUrl
相关推荐
firefaith 2020-10-30
libao 2020-09-16
Yyqingmofeige 2020-08-18
xiaoyuerp 2020-08-17
以梦为马不负韶华 2020-08-16
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20
yutou0 2020-10-17
JohnYork 2020-10-16