"do shell script" returns different from Terminal. Why?

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 shows it did. The 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!

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

MacBook (2006 August), Mac OS X (10.6.2)

Posted on Nov 21, 2009 9:05 PM

Reply
11 replies

Nov 24, 2009 5:29 PM in response to Ken Nellis

There is only one version of echo. It is being called two different ways. When the full path is used, it calls the program directly and passes all the arguments to it. When the full path is omitted, it has to use the shell to find echo, passing all the arguments to the shell, which then sends them on to echo.

When run with the full path (or from the terminal), "-n 'RolfAaberge'" results in "RolfAaberge". When called via AppleScript without the full path, the results are "-n 'RolfAaberg'"

Nov 24, 2009 6:36 PM in response to Ken Nellis

qen wrote:
Could the different versions of our software explain the difference?


It looks like it. When I do

do shell script "builtin echo -n 'RolfAaberge'"

in script editor, I get: "-n RolfAaberge"

If I just run "sh" and enter "echo -n 'RolfAaberge'", I still get "-n RolfAaberge". When running bash, I get "RolfAaberge". I know that "do shell script" uses sh.

These shell builtins are only for interactive use. You should always use the executable form from any kind of script.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

"do shell script" returns different from Terminal. Why?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.