echo -n aWord | md5 not returning expected result
When I pass this line echo -n aWord | md5
directly in shell I get the expected result - same as PHP md5('aWord')
- but when I call the code from a file I开发者_运维百科 get a different string.
Please help.
If you get following md5s:
=$ echo -n aWord | md5sum
a72ef25b2fa8080e6e0643c967284842 -
And from file:
=$ cat test.file
aWord
=$ md5sum test.file
1d03663ed556e850007c886ce5ad3ade test.file
This is because there is additional character in file - new line character:
=$ hexdump -C test.file
00000000 61 57 6f 72 64 0a |aWord.|
00000006
I can't comment but I do get the same result from a file than from the command line :
$ echo -n 'aWord' | md5sum
a72ef25b2fa8080e6e0643c967284842 -
$ echo -n 'aWord' > file
$ md5sum file
a72ef25b2fa8080e6e0643c967284842 file
精彩评论