Created
November 2, 2016 11:42
-
-
Save rhardih/639227e7a92343ceab7178a1900cad51 to your computer and use it in GitHub Desktop.
Bash utility shorthand to validate md5 checksums on files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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