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:
- If there is one, the executable specified in the shebang line is used.
- If there is none, the default (POSIX-like) shell
/bin/sh
is used.
- Thus, trying to invoke
*.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.