Rakan
Rakan

Reputation: 3

Comparing differences two files in Unix to produce bool

say I have two files.. file1 & file2, both have different names but the same content inside

I tried comparing them through

[[ file1 = file2 ]] 

& using

diff file1 file2
[[ echo $? ]]

however both return false.

Upvotes: 0

Views: 740

Answers (1)

Shawn
Shawn

Reputation: 52579

You're looking for cmp:

if cmp -s file1 file2; then
    echo "They're the same."
else
    echo "They're different"
fi

Upvotes: 1

Related Questions