Skip to content

Instantly share code, notes, and snippets.

@joeljuca
Last active May 24, 2017 22:26
Show Gist options
  • Save joeljuca/154cb69673fe8191dd3445a52fa026f6 to your computer and use it in GitHub Desktop.
Save joeljuca/154cb69673fe8191dd3445a52fa026f6 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Calculates the MD5 hash of a given file. It uses hashing utilities powered by
# operating systems, but wraps them into a consistent interface.
OS=$(
case $(uname) in
(Darwin*) echo "mac";;
(Linux*) echo "linux";;
# TODO: implement MD5 hashing on Windows
# (Windows*) echo "windows";;
(*) echo "linux";;
esac
)
case $OS in
mac )
md5 -q $1;;
linux )
echo md5sum $1 | sed -E 's/([a-z0-9]{32}).+$/\1/';;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment