且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Perl执行Python脚本时,为什么没有语法错误?

更新时间:2023-11-05 18:47:52

来自 perlrun

如果#!行既不包含单词"perl"也不包含单词"indir",则将执行以#!命名的程序,而不是Perl解释器.这有点奇怪,但是它可以帮助不使用#!的计算机上的人员,因为他们可以告诉程序其SHELL是/usr/bin/perl ,然后Perl会分派为其编程以使用正确的解释器.

If the #! line does not contain the word "perl" nor the word "indir" the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #! , because they can tell a program that their SHELL is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them.

例如,

$ cat a
#!/bin/cat
meow

$ perl a
#!/bin/cat
meow