2017-04-10 93 views

回答

1

使用||級聯。

diff -q file1 file2 || diff file1 file2 | mail -s "subject" "[email protected]" 

更多信息here

+0

奏效。似乎是比如果那麼陳述更好的解決方案。謝謝 – user3508766

+0

你也可以用'cmp'來比較文件,它比'diff -q'更輕便,更便於攜帶。 – ghoti

+0

做了一些研究,但我不會說cmp更快,來源:http://unix.stackexchange.com/questions/153286/is-cmp-faster-than-diff-q –

0

我能找到這個網絡,它的工作很大

command > file 
if [ -s file ] 
then 
    mailx -s "Subject" mailaddress <file.tmp 
fi 
rm file