![Check hash and then do a certain function](https://linux22.com/image/1487215/Check%20hash%20and%20then%20do%20a%20certain%20function.png)
I am trying to check a hash (doesn't matter which), and if a certain hash is met, then run certain commands.
Currently my code is
if [[ md5sum $file -ne $sum ]]
then
$commands
fi
However, bash refuses to run this, saying there are too many commands. How do I go about getting bash to run this simple if statement.
答案1
I cannot reproduce your error.
How about something like this?
file="file.txt"
sum="6f39af52b421a267040f88ba4bab95f4"
filesum=$(md5sum "$file" | cut -d" " -f1)
if [[ "$sum" != "$filesum" ]]
then
echo They are different!
fi