Need some help with bash

Need some help interpreting the result of this command. Results don’t seem to be intuitive.

  1. I ran the following and it evaluates the “if” block:

root@kali:/tmp# if [[ 0 ]]; then echo “return true”; else echo “return false”; fi

return true

  1. Now, I have two files with same content, test1.txt and test2.txt

root@kali:/tmp# echo test > test1.txt
root@kali:/tmp# cp test1.txt test2.txt

  1. I would expect the following to run the “if” block, but it executes the “else” block. I am not sure why, especially in step 1 the same thing executes the “if” block.

root@kali:/tmp# if [[ $(diff test1.txt test2.txt) ]]; then echo “return true”; else echo “return false”; fi

return false

I am missing something, but not sure what. Thanks in advance!

If two files are the same, diff provides nothing, not even 0, to stdout. Perhaps you can use md5sum with your If-then-else-fi.

Thank you so much - That helps. Figured it now!