Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SHA256 file hash value without a filename from "shasum" in macOS

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?

like image 942
KEINOS Avatar asked Oct 24 '25 12:10

KEINOS


1 Answers

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
like image 197
gromi08 Avatar answered Oct 26 '25 02:10

gromi08



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!