if ! cmp -s test.py test.py~
then
# restart service
fi
Breaking that down:
cmp -s test.py test.py~
returns true (0) if test.py and test.py~ are identical, else false (1). You can see this in man cmp
. The -s
options makes cmp
silent, so it doesn't give any output (except errors), but only an exit code.
!
inverts that result, so the if
statement translates to "if test.py and test.py~ are different".
ps: If you are not sure the 2nd file exists, you may want check that too. (cmp
still works in this case, but gives an error message, suppressing error message may be enough too (cmp ... 2>/dev/null
)