I am trying to obtain the hash of the contents stored in a variable created from a curl statement without outputting the curl into a file.
Basically I am trying to avoid:
curl website.com/file.exe >> tempfile.bin
md5sum tempfile.bin
The above provides the correct md5 hash. My approach (below) seemed to have work when testing plain text files, however when I attempted to download a binary and save it to a variable the hash was different than when I saved it to a file.
My attempt:
binary=$(curl website.com/file.exe)
echo $binary | md5sum
I think I may be missing a flag, or perhaps echo may not be the best way to do it. The important part of this challenge is not writing a file to disk, yet achieving the same md5 hash as if it were written to disk.
To also skip the step of using a temp variable, you can use process substitution:
md5sum <(curl website.com/file.exe)
or pipe to md5sum
directly:
curl website.com/file.exe | md5sum