我怀疑你可以让窗户接受一个shbang(#!).所以,如果你可以运行默认的shell(在我的情况下是bash),那么这在bash中有效:
@REM <<:END_REM
@echo off
echo This is DOS, this will only run in DOS.
perl -x -S %0 %*
goto over_nix
:END_REM
echo This is *NIX, this will only run in *NIX.
perl -x -S $0 $*
:<<__END__
#!perl
use 5.012;
use Data::Dumper;
say Dumper( \%ENV );
__END__
@REM <<:over_nix
:over_nix
Run Code Online (Sandbox Code Playgroud)
这需要在我的NIX路径中调用可执行文件'@REM'.
echo >> ~/bin/@REM
chmod +x ~/bin/@REM
Run Code Online (Sandbox Code Playgroud)