【发布时间】:2012-01-22 04:50:51
【问题描述】:
我有以下 Bash 函数:
checkForUpdates() {
checkLatest
ret=$?
if [ $ret != 0 ]; then
return $ret
fi
count=0
for i in $(ssh $__updateuser@$__updatehost "ls $__updatepath/*${latest}*"); do
file="${i##$__updatepath}"
echo "$file" >> $__debuglog
if [ -f $__pkgpath/$file ]; then
remoteHash=$(ssh $__updateuser@$__updatehost "md5sum -b < $__updatepath/${file}")
localHash=$(md5sum -b < $__pkgpath/$file)
echo "${remoteHash:0:32} = ${localHash:0:32}" >> $__debuglog
if [ "${remoteHash:0:32}" != "${localHash:0:32}" ]; then
files[$count]=$file
count=$(($count + 1))
echo "Hashes not matched, adding $i" >> $__debuglog
fi
else
files[$count]=$file
count=$(($count + 1))
echo "$file missing" >> $__debuglog
fi
done
# Verify that the files array isn't empty.
if [ $count != 0 ]; then
return 0
else
return 33
fi
}
由于某种原因,remoteHash/localHash 比较总是返回 true。我添加了回声,以便我可以看到散列的值,它们肯定是不同的,我不知道我哪里出错了。我尝试了不同的运算符但没有成功,这让我发疯!
【问题讨论】:
-
尝试使用
bash -x <command>运行。 -
不幸的是,我在这个脚本中大量使用了对话框,并且它不断删除输出。 -x 是否发送到标准输出或标准错误?如果它是 stderr,我可以将它通过管道传输到我相信的文件中。
-
没关系,这是标准错误。
-
不知道发生了什么,但它突然开始工作了。
-
我讨厌这种情况发生!不错的代码顺便说一句。祝你好运。
标签: linux bash variables scripting ubuntu