shelldiff

How to suppress all output of diff in shell scripting?


Greetings,

I was wondering if there was a way to suppress ALL output of the diff command so that it doesn't output the differences but only returns a success status?

diff $FILE1 $FILE2
if [ $? -ne 0 ];then
    echo Does not match output.
else
    echo Match.

Solution

  • If all you want to know is whether the two files differ, cmp is the better tool.

    if cmp -s file1 file2; then
       echo Files not changed.
    fi