栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Shell——判断文件是否存在并为空

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Shell——判断文件是否存在并为空

判断文件是否存在
file="config.yaml"
if [ ! -f "$file" ] # not exist
then 
 echo "file not exist"
 # do something 
 # touch "$file"
else
 echo "file exist"
fi
判断文件是否为空

如果文件为空,则一直下载,直到文件不为空为止。

file="config.yaml"
while [ ! -s "$file" ] # -s if file empty
 do
  echo "redownloading...."
  wget -O config.yaml "https://www.thismiao.xyz/link/21fQ=info"
 done
主代码
cd /home/vm/software/clash

file="config.yaml"


rm "$file"

if [ ! -f "$file" ] # not exist
then 
 echo "download the config file"
 while [ ! -s "$file" ] # -s if file empty
 do
  echo "redownloading...."
  wget -O config.yaml "https://www.thismiao.xyz/link/2?cl&log-level=info"
 done
fi

./clash -d .

参考文章:

  • shell中的循环语句、判断语句实例
  • 判断文件是否存在的shell脚本代码
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/680538.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号