On macOS (Mojave), doesn't the "shasum" command has an option, which returns only the hash value without the filename?
$ shasum -a 256 archive.tar.gz
35fe34e225a06d......00e72ee61a437b7226f9f archive.tar.gz
My current workaround which works in macOS' default state (w/no additional install):
$ shasum -a 256 archive.tar.gz | awk '{ print $1 }'
35fe34e225a06d......00e72ee61a437b7226f9f
$ php -r "echo hash_file('sha256', 'archive.tar.gz'), PHP_EOL;"
35fe34e225a06d......00e72ee61a437b7226f9f
But, I want to make it simpler if there's a command option for it.
Is there any command options or do I have to make an alias of the workarounds?
An array assignment works:
sha=($(shasum -a 256 archive.tar.gz))
echo $sha
35fe34e225a06d......00e72ee61a437b7226f9f
Or you can use cut:
shasum -a 256 archive.tar.gz | cut -f1 -d' '
35fe34e225a06d......00e72ee61a437b7226f9f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With