Solved: bash create md5 from string

Bash shell is the common linux command language.
Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Solved: bash create md5 from string

Post 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.
Last edited by mister_v on Wed Oct 09, 2013 7:45 pm, edited 1 time in total.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: bash create md5 from string

Post 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 }'
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Re: bash create md5 from string

Post by mister_v »

Thanks.

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