如何让 sha1sum 在 Mac OS X 上运行?

如何让 sha1sum 在 Mac OS X 上运行?

我有一个正在移植的应用程序,作为测试套件的一部分,我运行了sha1sum。我希望测试代码可以在我的所有平台上运行,并且不会因平台而异。Mac OS X 是第一个没有sha1sum应用程序的平台。不过我确实找到了一个shasum应用程序。所以我创建了一个符号链接:

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

但是,测试现在失败并出现 Perl 错误:

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

/usr/bin/shasum 的内容是:

#!/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

我怎样才能sha1sum在搜索路径中获得一个可以像shasum它一样工作的可执行文件?

答案1

shasum只是v5.12 或shasum5.12v5.16shasum5.16的包装器。perlperl

因此,将链接放在/usr/bin(而不是/usr/local/bin)中,并为其他两个特定版本创建链接,如下所示:

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

现在它可以工作了:

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

相关内容