Question below the code.
#!/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 $*
The goal is: Make the code works. What it does? Applies md5 to a folder, then compare the md5 values. It maintains a loop until the value is different (that means something on the folder happened), thus after 10 secs when the md5 calculates the hash it should be different, then the code ends.
Two Questions.
- Notice that there is a commented while there. If you uncomment the while and comment the for, you will notice the code stops working. Why? I tried different combinations for trying to make it work. I enclosed with quotes, used -eq, =, ==, etc. None worked. How could I make it work with a whole?
- The way the code it is now, if it is run then what I get as output is:
((: d41d8cd98f00b204e9800998ecf8427e == 97329acaae00bdf66e30ac53b49e1036: value too great for base (error token is “97329acaae00bdf66e30ac53b49e1036”)
Thus, how can I fix this is the second question and why this is happening.
Thank you!
The issue you are having with the (updated) posted code is that you are using a
forloop when awhileloop works.The following code works for me. I simply changed the
forloop to awhileloop.The reason the while loop wasn’t working is because you were missing spaces between the square brackets and the expression.