Search code examples
bashffmpegcmp

How does CMP pass comparison value to the next line in a bash script?


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?


Solution

  • 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