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

Shell——判断文件是否存在并为空,第1张

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脚本代码

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5681119.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存