vmonteco vmonteco - 1 year ago 58
Bash Question

How to hash a string without adding a trailing '\n' to it?

I'm trying to use md5 in both python and shell (zsh on OSX).

I got this :

In python :

>>> hashlib.md5("zoo".encode('utf-8')).hexdigest()

with Zsh :

$ echo "zoo" | md5

Since I also have :

>>> hashlib.md5("zoo\n".encode('utf-8')).hexdigest()

in Python, I think that my zsh command adds a (unwanted) trailing '\n' to the string before hashing it.

Why does this happen, and how could I avoid this?

Answer Source

here you go:

kent$  echo -n 'zoo'|md5sum

kent$  echo  'zoo'|md5sum