I am trying to use an if statement to check two files to see if they are the same using md5sum. The code below seems to me to be fine, but when I run it, the output is always "The files are the same", even when I deliberately make them different. Why is this?
if ["$(md5sum file2)" != "$(md5sum file2)"]; then
echo "The files are different."
else echo "The files are the same"
When trying to run the code in a terminal, I also sometimes get a message like this:
[227ba58f8f59da4329683682565b1e4f: command not found
...as if the shell is trying to interpret the md5sum output as a command, which doesn't make sense. I also tried piping the commands through awk to eliminate the 2nd field that md5sum automatically generates, in an attempt to reduce confusion with the white spaces. That didn't work either. Any help would be appreciated.