比较输出而不是命令 [英] Compare output rather than command
本文介绍了比较输出而不是命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试创建脚本以读取远程文件并检查md5校验和,并在出现不匹配但收到我不理解的错误时发出警报.
Trying to create a script to read a remote file and check the md5 checksum and alert if a mismatch yet getting an error I can't understand.
#!/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
这将返回line 4: [6135222a12f06b2dfce6a5c1b736891e: command not found
我曾尝试在$ LOCALMD5周围使用'或',但似乎从未能够使用它来比较输出.我在做什么错? 谢谢
I've tried using ' or " around the $LOCALMD5 but never seem able to get this to compare the outputs. What am I doing wrong? Thanks
推荐答案
尝试;
if [ "$LOCALMD5" == "$REMOTEMD5" ]
应该会更好.
我认为您的代码中==和!=颠倒了.
I think you got == and != reversed in your code.
这篇关于比较输出而不是命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文