Say I have
shasum=$(sha1sum <file>)
how can I compare that value to a sha1sum from another file:
if [[ $shasum == `cat <other-file>` ]]; then
echo "values are the same"
fi
that can't be right, anybody know?
If I understand correctly, you have to files, say test1.txt & test2.txt, and you want to compare the sha1 sum of thoose files.
You need to get the sha1sum of both of thoose files:
shasum1=$(sha1sum test1.txt)
shasum2=$(sha1sum test2.txt)
Then you compare thoose values:
if [ "$shasum1" = "$shasum2" ]; then
echo "Files are the same!"
else
echo "Files are different!"
fi
However, you shouldn't use SHA1 anymore.
Here's a full solution
# .SUMMARY
# Check if two files have the exact same content (regardless of filename)
#
file1=${1:-old_collectionnames.txt}
file2=${2:-new_collectionnames.txt}
# Normal output of 'sha1sum' is:
# 2435SOMEHASH2345 filename.txt
# Cut here breaks off the hash part alone, so that differences in filename wont fail it.
shasum1=$(sha1sum $file1 | cut -d ' ' -f 1)
shasum2=$(sha1sum $file2 | cut -d ' ' -f 1)
if [ "$shasum1" = "$shasum2" ]; then
echo "Files are the same!"
else
echo $shasum1
echo $shasum2
echo "Files are different!"
fi