I have Strawberry Perl and have msys Perl 5.6 removed.
Now perl
will invoke Strawberry (due to PATH
env) but how do I map the perl
command in .pl
or other Perl script files which have #!/bin/perl
or #!/usr/bin/perl
shebang lines?
I was thinking of making a hardlink to perl.exe in msys/bin or merge the whole Strawberry inside the msys directory, but I'm not sure.
During installation, we recommend installing it in C:\Strawberry . This is the default for the MSI package. Connect your computer to the Internet so you are able download any required Perl modules from CPAN.
Just open a command prompt (in Windows, just type cmd in the run dialog and press Enter. If you're on a Mac or on Linux, open a terminal window). and press Enter. If Perl is installed, you receive a message indicating its version.
The solution is to create a symlink to the Strawberry Perl executable from within MSYS Tip of the hat to smaudet for his input:
First, remove or rename the Perl executables that the MSYS installation came with, if any (which the OP has already done); e.g.:
mv /usr/bin/perl /usr/bin/perl.msys
mv /usr/bin/cpan /usr/bin/cpan.msys
Then create a symlink to Strawberry Perl's executable in its place:
ln -s /c/strawberry/perl/bin/perl.exe /usr/bin/perl
# Unfortunately, doing the same for `cpan` doesn't work directly, because
# Strawberry Perl's `cpan` executable is a *batch* file, `cpan.bat`, which
# cannot be directly invoked from MSYS.
# To invoke it from MSYS (assuming it is in the %PATH%):
# cmd /c 'cpan.bat ...'
# With an explicit path:
# cmd /c 'c:\strawberry\perl\bin\cpan.bat ...'
#
# Here's how to create a stub script that still allows invocation as
# `cpan`:
echo 'cmd /c "C:\strawberry\perl\bin\cpan.bat $*"'>/usr/bin/cpan && chmod +x /usr/bin/cpan
Once the /usr/bin/perl
symlink is in place, existing scripts with shebang lines #!/usr/bin/perl
and #!/bin/perl
will work again (the latter also works, because /bin
and /usr/bin
are effectively the same location in MSYS).
Note that scripts written with the more flexible shebang line #!/usr/bin/env perl
do not need this, because env
will directly find Strawberry Perl's perl.exe
in the path.
Some background:
Unix-emulation environments such as MSYS and Cygwin do not respect Windows' %PATHEXT%
variable to determine what executable to invoke a (non-binary) file with. In other words: filename extensions have no meaning with respect to execution there.
Instead, they solely go by whether the file has a shebang line:
/bin/sh
is used.
*.bat
or *.cmd
files directly fails, because they don't have a Unix shebang line and are therefore executed by /bin/sh
rather than cmd.exe
.Unlike in Windows, this also works with (executable) files that have no filename extension at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With