Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by Rinzwind, enzotib, fossfreedom, hhlp, htorque Dec 19 '11 at 23:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

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.

share|improve this answer
    
echo will append a trailing newline then, use echo -n $VAR instead. –  math Dec 14 '11 at 16:41

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)

share|improve this answer
    
not -e, but -n –  arrange Dec 10 '11 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 '11 at 21:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.