"do shell script" returns different from Terminal. Why

(I thought it would take longer to get authorized, so I posted this question on discussions.apple.com in the meantime. Sorry for the duplication. My question better fits this community, I think.)

Hi all,

I’m a novice by all means, so I might be missing the obvious. However, I wanted to have a little AppleScript that returns the SHA1 hash of a string. My results were different from other ways of getting the same hash, so in the end I went and copied into Terminal what AppleScript Editor shows did with the script. The returned hashes are different, which I don’t understand. I tried to research some character encoding issues, but did not find anything (everything should be Unicode, and that’s it).

Could you help me sort out what’s going on, and how I could get the hash I want (the same as in Terminal)? Thanks!

Laszlo

Excerpt from AppleScript Editor Result pane after run:
do shell script “echo -n ‘RolfAaberge’|openssl sha1”
→ “683acf2937e0a3cd7817a6cd466104b46204c575”

Excerpt from Terminal after run:
echo -n ‘RolfAaberge’|openssl sha1
b2f0b01f414f709f311f233633b91bdd5c08ae6a

Model: MacBook
AppleScript: 2.1.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)

You’ve already got a solution: use /bin/echo -n or printf in place of the default bash echo. Its an encoding problem and a bug IMHO.

Thank you, Adam. Indeed, I should have posted on this forum too that I got a solution on discussions.apple.com.

Perhaps somebody at Apple took notice too.

Thank you once more,

Laszlo