Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent External Command Output

Tags:

md5

perl

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

like image 366
sidyll Avatar asked Dec 03 '25 17:12

sidyll


1 Answers

When in the /bin/sh shell on mac, echo -n doesn't not print out the newline like it does in /bin/bash. You can see this if you drop into /bin/sh and run echo -n a, your output should look like this:

sh-3.2$ echo -n a
-n a

so you're literally getting -n a instead of the desired a. As perl system runs /bin/sh to evaluate your command, -n a is being passed into md5 instead of your desired a

like image 159
hexist Avatar answered Dec 06 '25 08:12

hexist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!