【发布时间】:2011-05-04 07:37:05
【问题描述】:
目前,我的脚本下载html页面的源代码并将其保存为plist,它检查plist和模板文件的SHA哈希,如果哈希不同,它会删除plist中的一些东西,否则它退出了。
我想要实现的是一种无限的while循环。虽然 SHA 哈希值相同,但它会再次下载 html 源代码,检查 SHA 哈希值,当检测到 SHA 哈希值不同时,它会删除 plist 中的一些键。
#!/bin/sh
file="/a/path/file"
a="Key1"
b="Key2"
c="Key3"
d="Key4"
declare -a array=($a $b $c $d);
cd /a/path
if [ ! -e $file.plist ]; then
curl http://something.com/ > file.plist
fi
new=`shasum file.plist`
old=`shasum orig_file.plist` # this is a template file.
if [ "$old" != "$new" ]; then
echo "Hash mismatch !"
for i in "${array[@]}"
do
defaults delete $file $i
done
else
exit 0
fi
【问题讨论】:
标签: macos bash curl while-loop