Echo hash only from shasum

hashsum

Is there a way to get shasum to only print the hash?

I know this can be achieved by piping the output to another program, e.g.

shasum something | cut -d' ' -f1

Is there a way to achieve this only using shasum, without having to pipe the result somewhere else?

Best Answer

No, shasum always prints the filename of the file that it computes the hash for, or - if it reads from standard input.

To avoid the pipe, you could use

perl -MDigest::SHA -e '$s=Digest::SHA->new(); $s->add(<>); print $s->hexdigest(),"\n"' filename