[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>Shell语句
Shell环境根据命令执行后的返回状态值($?)来判断是否执行成功,当返回值为0(真true)时表示成功,返回值为非0值(假false)时表示失败或异常。
<>一、条件语句
<>(1)test命令
格式一:test 条件表达式 格式二:[ 条件表达式 ]
<>(2)文件测试
格式:[ 操作符 文件或目录 ] 常用的操作符: -e:测试目录或文件是否存在(Exist)。 -d:测试是否为目录(Directory)。
-f:测试是否为文件(File)。 -r:测试当前用户是否有权限读取(Read)。 -w:测试当前用户是否有权限写入(Write)。
-x:测试是否设置有可执行(Excute)权限。
<>(3)整数值比较
格式:[ 整数变量1 操作符 整数变量2 ] 常用的操作符: -eq:等于 -ne:不等于 -gt:大于 -lt:小于 -le:小于等于 -ge:大于等于
<>(4)字符串比较
格式1: [ 字符串1 = 字符串2 ] 或 [ 字符串1 == 字符串2 ] [ 字符串1 != 字符串2 ] 格式2: [ -z 字符串 ]
#检查字符串是否为空(Zero),对于未定义或赋予空值的变量将视为空串 [ -n 字符串 ] #检查是否有字符串存在
<>(5)逻辑测试
格式1:[ 表达式1 ] 操作符 [ 表达式2 ] / [[ 表达式1 操作符 表达式2 ]] 格式2:命令1 操作符 命令2 常用的操作符: -a或&&
:逻辑与,“而且”的意思,前后条件需都成立 -o或|| :逻辑或,“或者”的意思,只需前后条件中一个成立 ! :逻辑否
<>二、if语句
<>(1)单分支 if 语句
if 条件测试操作 then 命令序列 fi
<>(2)双分支 if 语句
if 条件测试操作 then 命令序列 1 else 命令序列 2 fi
例子:
#!/bin/bash read -p "输入性别" a if [ $a = "男" ] then echo "$a 组" else echo "女 组"
fi
<>(3)多分支 if 语句
if 条件测试操作 1 then 命令序列 1 elif 条件测试操作 2 then 命令序列 2 else 命令序列 3 fi
例子:
#!/bin/bash read -p "请输入您的分数(0-100): " z if [ $z -ge 85 ] && [ $z -le 100 ]
then echo "$z 分,优秀!" elif [ $z -ge 70 ] && [ $z -le 84 ] then echo "$z 分,合格!"
else echo "$z 分,不合格!" fi
<>三、case语句
case 变量值 in 模式 1) 命令序列 1 ;; 模式 2) 命令序列 2 ;; * ) 默认命令序列 esac
例子:
#!/bin/bash read -p "请输入您的分数(0-100): " w [[ $w -ge 85 && $w -le 100 ]] &&
a="yx" [[ $w -ge 70 && $w -lt 85 ]] && a="hg" [[ $w -ge 0 && $w -lt 70 ]] &&
a="bhg" case $a in yx) echo " 优秀!" ;; hg) echo "合格!" ;; bhg) echo "不合格!" ;; *)
echo "输入有误!" esac