Check hash and then do a certain function

Check hash and then do a certain function

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

相关内容