I'm entering:

appletree:~ somename$ shasum -a 512 <<< test

And the output is:

0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123  -

Then I go to some online hash generators and enter "test" too. Their answers are:





So the online generators agree. What am I missing in the Mac console command?

I was reading the man pages. I see it's implemented using a Perl library. However, I think sha512 would be a unique designation, so I have to dig deeper.

There seems to be a duplicate question: Why is my command-line hash different from online MD5 hash results?. While the other question is in the same context, which is unexpected whitespace, it emerges from a different situation.

  • <<< is a here string, and there is a design choice for how here strings add newline.
  • echo 'bla' | means piping, which invokes sub shells, and also has arguments for how to handle newline. Here it seems you have to consider the shell version.
  • Thanks a lot to sideshowbarker and Spiff. Whitespace strikes again ^^ ^^ – peter_the_oak Feb 18 '17 at 10:01
  • 5
  • Note that a here string is intended to be exactly identical to a one-line here document, and a here document always ends with a newline. – chepner Feb 19 '17 at 2:45
  • I am not new to shell, but here are some sophisticated details and news for which I'm grateful. So thanks for all the comments and answers. – peter_the_oak Feb 19 '17 at 8:00
  • So we found that Mac's shasum command isn't any different. The issue was technically user error, and had to do with the data being passed, not the program. May I suggest renaming the question, to "Why do I get different results from Mac's shasum..." That way, people can instantly suspect a user-created issue. (Had I seen that, I might have been less inclined to check this question out right now. As currently titled, "What distribuishes the mac shell shasum from other shasum calculators?", I came here to learn about possible Mac-specific differences, which isn't what this actually ended up as – TOOGAM Feb 19 '17 at 22:04
up vote 32 down vote accepted

The input to the shasum invocation in the question is test\n (with a newline), not test.

If you give test with no newline to shasum you’ll get the same output as the online tools you cite:

$ echo -n "test" | shasum -a 512
ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff  -

By the way, I think there’s nothing special or MacOS-specific about the shasum found on MacOS; I think shasum is part of the standard Perl distro— installed along with, e.g., the perl command.

Try this:

hexdump -C <<< test

Knowing Unix shells, you're probably getting an unwanted 0x0a at the end of that string.

  • 2
    od will label control characters and make the more apparent; try: od -t a -t x1 <<< test (never really used hexdump), – toddkaufmann Feb 20 '17 at 9:37

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.