Skip to content

Instantly share code, notes, and snippets.

@rhardih
Created November 2, 2016 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhardih/639227e7a92343ceab7178a1900cad51 to your computer and use it in GitHub Desktop.
Save rhardih/639227e7a92343ceab7178a1900cad51 to your computer and use it in GitHub Desktop.
Bash utility shorthand to validate md5 checksums on files
#!/usr/bin/env bash
# md5c
#
# Perform md5 checksum validation of a file against
# a specified md5 hash.
#
# usage: md5c filename hash
function md5c {
filename="$1"
md5_hash="$2"
md5_output="$(md5 $1)"
diff="${md5_output%"$md5_hash"}"
expected="MD5 ($1) = "
if [ "$diff" = "$expected" ]; then
echo "Checksum verified."
else
echo "Checksum failed."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment