0

I want to compare the output of two framemd5 (decoded md5 of every video frame) digests. https://stackoverflow.com/a/12736416/2188572

The cmp script works perfectly for me. I know next to nothing about coding, so I want to educate myself on what's happening, and I can't figure out from SO or googling.

It seems like the script should require more input from me, like I should have to stipulate(apologies for awful pseudo code)

cmp file1 file 2
if cmp produces a difference;then
else 

It seems that just entering "if cmp file1 file 2" automatically produced the equivalent of a YES or NO and stores that info for the then, else etc?

Community
  • 1
  • 1
Tandy Freeman
  • 528
  • 5
  • 15

1 Answers1

2

if will evaluate any command returning a zero or non zero status, executing the then branch if the status is 0, or the else branch otherwise, so you can simply write:

 if cmp -s file1 file; then
    echo "files are equal"
 else
     echo "files are different"
 fi
Mario Zannone
  • 2,843
  • 12
  • 18
  • Thank you! So it's actually the `if` that is passing the result to the next line, not cmp? This is exactly the explanation I required. – Tandy Freeman Aug 22 '15 at 13:31