3

Possible Duplicate:
How to get the MD5 hash of a string directly in the terminal?

I have a given variable and I have to calculate its md5sum. I have tried with "md5sum $variable", but it doesn't work.

johnny
  • 451

2 Answers2

3

md5sum takes filenames as parameters.

Iif you have a string you want to calculate the hash of, you need to pass it to md5sum's standard input via a pipe:

echo -n $variable | md5sum

(-n to suppress adding a newline)

Caesium
  • 15,807
tumbleweed
  • 8,026
0

I think you could try this:

echo -n "$VARIABLE" | md5sum

As suggested in comments, echo -n should will not add a new line. Also, using quotes will keep new lines as in original content.

Alexandre
  • 1,948