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.

0

2 Answers 2

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)

2
  • not -e, but -n
    – arrange
    Dec 10, 2011 at 19:51
  • Also, you need to quote "$variable", otherwise leading and trailing spaces are not taken into account, as multiple consecutive spaces inside the content of variable.
    – enzotib
    Dec 10, 2011 at 21:30
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.

1
  • echo will append a trailing newline then, use echo -n $VAR instead.
    – math
    Dec 14, 2011 at 16:41

Not the answer you're looking for? Browse other questions tagged .