No sha256sum in MacOS
The CoreUtils package is also published as a Brew formulae. So if you have Brew installed you can also just run:
brew install coreutils
Then add PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
to ~/.bashrc
, run source ~/.bashrc
and you're done.
After investigating a little, I found a ticket in an unrelated software in GitHub sha256sum command is missing in MacOSX , with several solutions:
installing coreutils
sudo port install coreutils
It installs
sha256sum
at/opt/local/libexec/gnubin/sha256sum
As another possible solution, using
openssl
:
function sha256sum() { openssl sha256 "$@" | awk '{print $2}'; }
- As yet another one, using the
shasum
command native to MacOS:
function sha256sum() { shasum -a 256 "$@" ; } && export -f sha256sum
Supplemental Answer to Mig82's, whose answer handles the g-prefix for all executables in coreutils. I offer a tightly-scoped solution.
After coreutils installing with
brew install coreutils
Results in ls /usr/local/bin/gsha*
will list the g-prefixed executables:
/usr/local/bin/gsha1sum
/usr/local/bin/gsha224sum
/usr/local/bin/gsha256sum
/usr/local/bin/gsha384sum
/usr/local/bin/gsha512sum
The solution is to create a symbolic link to the ones you want using a non-prefixed name (or take a risk in breaking some programs that rely on BSD executables and use the no g prefix Homebrew option)
Example
shaarray=(\
/usr/local/bin/gsha1sum
/usr/local/bin/gsha224sum
/usr/local/bin/gsha256sum
/usr/local/bin/gsha384sum
/usr/local/bin/gsha512sum
)
function installsha() {
for i in "${shaarray[@]}"
do
printf "$i\n" | perl -pe 'printf $_; s/gsha/sha/' | xargs -n 2 ln -s
done
}