判断文件是否存在

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 .

参考文章: