The terminal transcript speaks for itself:
iMac:~$ echo -n a | md5 0cc175b9c0f1b6a831c399e269772661 iMac:~$ perl -e 'system "echo -n a | md5"' c3392e9373ccca33629d82b17699420f
Note that the MD5 hash of a is 0cc175b9c0f1b6a831c399e269772661, the first
result. Why does it turns out to be different when the same command is called
by perl?
By the way, perl is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level. And the system: Mac OS 10.8, Darwin 12.0
When in the
/bin/shshell on mac,echo -ndoesn’t not print out the newline like it does in/bin/bash. You can see this if you drop into/bin/shand runecho -n a, your output should look like this:so you’re literally getting
-n ainstead of the desireda. As perl system runs/bin/shto evaluate your command,-n ais being passed into md5 instead of your desireda