在代码下面提问。
#!/bin/sh
check() {
dir="$1"
chsum1=`find ~/folder -type f -exec cat {} \; | md5`
chsum2=$chsum1
for (( ; 0x$chsum1 == 0x$chsum2; ))
do
echo "hello"
sleep 10
chsum2=`find ~/folder -type f -exec cat {} \; | md5`
done
echo "hello"
#eval $2
}
check $*目标是:使代码工作。它能做什么?将md5应用于文件夹,然后比较md5值。它会保持一个循环,直到值不同(这意味着文件夹上发生了一些事情),因此在10秒之后,当md5计算出它应该不同的散列时,代码就结束了。
两个问题。
。
(:d41d8cd98f00b204e9800998ecf8427e == 97329acaae00bdf66e30ac53b49e1036:基值太大(错误标记为"97329acaae00bdf66e30ac53b49e1036")
Thus, how can I fix this is the second question and why this is happening.谢谢!
发布于 2012-06-05 05:07:14
(更新的)发布代码存在的问题是,当for循环工作时,您使用的是while循环。
下面的代码适用于我。我只是将for循环更改为while循环。
#!/bin/sh
check() {
dir="$1"
chsum1=`find ~/NASAtest -type f -exec cat {} \; | md5`
chsum2=$chsum1
while [ $chsum1 == $chsum2 ]
do
echo "hello"
sleep 10
chsum2=`find ~/NASAtest -type f -exec cat {} \; | md5`
done
echo "hello"
#eval $2
}
check $*while循环不能工作的原因是,在方括号和表达式之间缺少空格。
发布于 2014-01-13 22:20:17
您可以通过将Z放在值的前面,并将Z作为字符串进行比较,从而消除您正在比较的变量的格式或类型(值太大而不适合基本值)。
# read or operation to define $file1 & $file2 here ...
val1=`md5sum ${file1} | awk '{print $1}'`
val2=`md5sum ${file2} | awk '{print $1}'`
tmpval="Z${val1}" ; val1="${tmpval}"
tmpval="Z${val2}" ; val2="${tmpval}"
if [[ "$val1" -eq "$val2" ]] ; then
# files are the same, do operation here ..
fi
done发布于 2012-06-05 05:08:05
,而$chsum1 == $chsum2执行一些事情
这需要看起来像这样(包括换行符)
while [ $chsum1 == $chsum2 ]
do
(perform some stuff)
done注意方括号和do/done块周围的空格,而不是end。
https://stackoverflow.com/questions/10891800
复制相似问题