How to get sha1sum to work on Mac OS X?

1

2

I have an application that I'm porting and as part of the test suite, I run sha1sum. I'd like to have test code that works on all my platforms and not vary across platforms. Mac OS X, is the first platform without a sha1sum application. I did find a shasum application though. So I created a symbolic link:

cd /usr/local/bin; ln -s /usr/bin/shasum sha1sum

However, the test now fails with a Perl error:

bash-3.2$ sha1sum -c files.sha1sum
perl version 5.16.2 can't run /usr/local/bin/sha1sum.  Try the alternative(s):

(Error: no alternatives found)

Run "man perl" for more information about multiple version support in
Mac OS X.

bash-3.2$ shasum -c files.sha1sum
smallData.txt: OK

The contents of /usr/bin/shasum are:

#!/usr/bin/perl

=for comment

The contents of this script should normally never run!  The perl wrapper
should pick the correct script in /usr/bin by appending the appropriate version.
You can try appending the appropriate perl version number.  See perlmacosx.pod
for more information about multiple version support in Mac OS X.

=cut

use strict;
use Config ();

my @alt = grep {m,^$0\d+\.\d+(?:\.\d+)?$,} glob("$0*");
print STDERR <<"EOF-A";
perl version $Config::Config{version} can't run $0.  Try the alternative(s):

EOF-A
if(scalar(@alt) > 0) {
    for(@alt) {
    my($ver) = /(\d+\.\d+(?:\.\d+)?)/;
    print STDERR "$_ (uses perl $ver)\n";
    }
} else {
    print STDERR "(Error: no alternatives found)\n";
}
die <<'EOF-B';

Run "man perl" for more information about multiple version support in
Mac OS X.
EOF-B

How can I get a sha1sum executable in my search path that will work like shasum does?

WilliamKF

Posted 2014-03-27T19:14:30.223

Reputation: 6 916

This might be of use: https://raam.org/2008/howto-install-md5sum-sha1sum-on-mac-os-x/

– David – 2015-12-03T22:45:49.330

Answers

1

The shasum is just a wrapper for either shasum5.12 or shasum5.16 for perl v5.12 or perl v5.16.

Therefore, place the link in /usr/bin (instead of /usr/local/bin) and create links for the other two version specific ones too like this:

cd /usr/bin
ln -s shasum sha1sum
ln -s shasum5.12 sha1sum5.16
ln -s shasum5.16 sha1sum5.16

Now it works:

bash-3.2$ sha1sum -c files.sha1sum
smallData.txt: OK

WilliamKF

Posted 2014-03-27T19:14:30.223

Reputation: 6 916

Doesn't work for me: perl version 5.18.2 can't run /usr/bin/sha1sum. Try the alternative(s): – sleepycal – 2015-01-16T11:11:15.907

@sleepycal, did your comment get cut off? What alternatives were you referring to? – David – 2015-12-03T22:44:40.903