目录

相关语法

判断文件是否存在

判断文件是否为空

实例


相关语法

[ -f FILE ]  如果 FILE 存在且是一个普通文件则为真。  

[ -s FILE ]  如果 FILE 存在且大小不为0则为真。  

判断文件是否存在

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" ] 
 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 .

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐