Shellscript action if two files are different
if ! cmp test.py test.py~ >/dev/null 2>&1then # restart servicefi
Breaking that down:
cmp test.py test.py~
returns true (0) if test.py and test.py~ are identical, else false (1). You can see this inman cmp
.!
inverts that result, so theif
statement translates to "if test.py and test.py~ are different".- The redirects
>/dev/null 2>&1
send all output ofcmp
to null device, so you just get the true/false comparison result, without any unwanted noise on the console.