“echo” and “md5sum”

A problem I faced when I attempted to manually set a password for my user in Water, was that I could not login. I created the md5 sum of my password, running:

$ echo mypassword|md5sum

and pasted it into the MySQL field of phpMyAdmin. After many login failures and enough searching about what is to blame, Kostis90gr found out that “echo”, is outputting a newline at the end of the string, so the md5 sum produced from the command above, was different than the one produced from PHP’s md5() function, simply because they were given different input. So, the right thing to do, is to pass “echo” the “-n” option, like:

$ echo -n mypassword|md5sum

which prevents “echo” from outputting a newline at the end of the string.
I hope this post is helpful, because my unawareness of this “echo”‘s little “particularity”, caused me quite enough frustration.

5 Responses to ““echo” and “md5sum””

  1. kostis90gr says:

    A real piss-off!

  2. dionyziz says:

    kostis90gr: If echo was not outputting a newline at the end, all your echo statements would end up being in the same line as the next prompt. You don’t really want that, do you? :P

  3. Indy says:

    You mean, like that?

    indy@latitude:~/Desktop$ echo -n Hello, World!
    Hello, World!indy@latitude:~/Desktop$

    :P

  4. dionyziz says:

    Exactly, Indy. And you don’t want “md5sum” to ignore newlines either, as it’s usually used to calculate the md5 sum of binary files ;-)

  5. Indy says:

    Or, why not, big text documents as well (like XML documents or other similar stuff).

Leave a Reply