Page 1 of 1

Solved: bash create md5 from string

Posted: Wed Oct 09, 2013 7:35 pm
by mister_v
Hi,

I want to use bash to create a md5sum from a string.
I tried md5sum, but it expect a file as input.

Re: bash create md5 from string

Posted: Wed Oct 09, 2013 7:38 pm
by chris
You can pipe it using |

Code: Select all

echo -n "test" | md5sum
(You need option -n because else md5sum will calculate the string with newline char.)

should give something like:

Code: Select all

098f6bcd4621d373cade4e832627b4f6  -
if you don't like the - at the end

Code: Select all

echo -n "test" | md5sum | gawk '{ print $1 }'

Re: bash create md5 from string

Posted: Wed Oct 09, 2013 7:45 pm
by mister_v
Thanks.

Indeed without -n the bash md5 check is not the same as with my PHP md5 check.