8

I want to find the md5 hash of the string "a", but running echo "a" | md5sum gives me another hash than what I get if I search the internet (for example using DuckDuckGo or the first search result I found).

Running echo "a" | md5sum gives me "60b725f10c9c85c70d97880dfe8191b3", but it should be "0cc175b9c0f1b6a831c399e269772661".

If I make a reverse hash lookup for "60b725f10c9c85c70d97880dfe8191b3", I do however get "a".

14

The reason for the hashes being different is that echo includes a newline at the end of the output string to make it pretty. This can be prohibited by the -n flag (if your implementation of echo supports it), or by using another program (like printf):

> echo "a" | md5sum   
60b725f10c9c85c70d97880dfe8191b3  -

> echo -n "a" | md5sum
0cc175b9c0f1b6a831c399e269772661  -

> printf "a" | md5sum 
0cc175b9c0f1b6a831c399e269772661  -
  • 1
    echo adds a newline to the output to make it a complete line, not to make it pretty. – Kusalananda Jul 12 '18 at 8:56
  • @Kusalananda Typing in printf text makes the text appear infront of the next prompt line. – neverMind9 Nov 11 '18 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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