I use the following script to compare to folders:
if diff "/home/folder1/" "/home/folder2/" &> /dev/null ; then
echo "Files in the two folders are the same"
else
echo "Files in the two folders are NOT the same"
fi
Is there a brief way of explaining what the "&> /dev/null" actually does, does it return a boolean value of true/false?
And my main question: What would the opposite be? I mean, say I want the "if diff" question to be "Is the content of the two folders NOT the same?"
!
variants and rather switch thethen
and theelse
blocks to achieve the same effect. If I have not both blocks, then I do not even use anif
because I can achieve the same by usingdiff … && echo "then block!"
ordiff … || echo "else block!"
(I tend to read the||
in this case as otherwise). Using the redirect then makes it look like this:diff … &>/dev/null || echo "else block!"
And you can use braces to group several commands, if your blocks are larger. – Spigot