I have the following bash script.
while IFS= read -r filename;
do [[ $(md5 path/to/"$filename-orig") = $(md5 path/to/"$filename") ]] || echo $filename differs;
done < path/to/list-of-files-to-compare.txt
It's supposed to compare two files (by computing their MD5 hash digest) then report if they are different. It gets the files to compare from a list.
The problem is that if the file I am trying to read is at, say,
path/to/foo-orig.js
the script will look for the file at
path/to/foo.js-orig
and, obviously, this throws an error and fails.
How do I correct this bug in my script so that I handle the .js
extension correctly?
Edit
TL;DR:
Given a string foo.bar
how can I get foo-orig.bar
?