Compare output rather than command

Try;

if [ "$LOCALMD5" == "$REMOTEMD5" ]

which should work better.

Edit: I think you got == and != reversed in your code.


I think it should be like this:

#!/bin/sh
REMOTEMD5=$(ssh user@host 'md5sum file.txt')
LOCALMD5=$(md5sum 'file.txt')
if [ "$LOCALMD5" == "$REMOTEMD5" ]
then
  echo "all OK"
else
  echo -e "no match, Local:"$LOCALMD5"\nRemote:"$REMOTEMD5
fi

The space between the bracket and the value is important!


[ isn't bash syntax, it is a command. So you must have a space between it and its first argument $LOCALMD5. There also needs to be a space between $REMOTEMD5 and ].