I'm trying to compare a list of files in two repos to try to flag which ones have changed. The problem is, my code says they are all different. But inspecting each hash digest shows that many digests are identical.
while IFS= read -r filename;
do
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# inspecting the digest of each file individually #
# shows many files are identical and so are the digests #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
md5 old/$filename; # a456cca87913a4788d980ba4c2f254be
md5 new/$filename; # a456cca87913a4788d980ba4c2f254be
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# the below conditional is only supposed to echo "differs" #
# if the two digests are different #
# but, instead, it echoes "differs" on every file comparison #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
[[ $(md5 old/$filename) = $(md5 new/$filename) ]] || echo differs; # differs
done < files-to-compare.txt
How can I fix this bug and only get the files that are different to report?
Edit
Also, note using ==
instead of =
as in
$(md5 old/$filename) == $(md5 new/$filename) ]] || echo differs;
yields exactly the same buggish output.
Edit2
A comment suggests using quotes. That also doesn't work.
"$(md5 old/$filename)" == "$(md5 new/$filename)" ]] || echo differs;