Perl基于shebang行发送给其他解释器?
当我不小心用perl运行了一个bash脚本,它。。。工作。通过进一步的实验,perl似乎可以读取脚本的shebang并发送给正确的解释器:Perl基于shebang行发送给其他解释器?,perl,shebang,Perl,Shebang,当我不小心用perl运行了一个bash脚本,它。。。工作。通过进一步的实验,perl似乎可以读取脚本的shebang并发送给正确的解释器: $ cat /tmp/ohhai.sh #!/bin/bash echo ohhai bash $ perl /tmp/ohhai.sh ohhai bash 嗯。。。胡特 为了确保我没有发疯,我尝试与其他解释器一起这样做,并确认这只是一个perl ism: $ python /tmp/ohhai.sh File "/tmp/ohhai.sh",
$ cat /tmp/ohhai.sh
#!/bin/bash
echo ohhai bash
$ perl /tmp/ohhai.sh
ohhai bash
嗯。。。胡特 为了确保我没有发疯,我尝试与其他解释器一起这样做,并确认这只是一个perl ism:
$ python /tmp/ohhai.sh
File "/tmp/ohhai.sh", line 2
echo ohhai bash
^
SyntaxError: invalid syntax
这有文件记录吗?这是新事物/旧事物吗。。。为什么?
“瑞士陆军电锯”的确如此。这是一个古老的东西,记录在: 如果
#代码>行不包含单词“perl”或单词“indir”以命名的程序执行代码>而不是Perl解释器。这有点奇怪,但它可以帮助那些不执行#的机器上的人代码>,因为它们可以告诉程序它们的SHELL是/usr/bin/perl,然后perl会为它们将程序分派到正确的解释器
$ cat /tmp/ohhai.groovy
#!/usr/bin/groovy
println 'ohhai groovy'
$ perl /tmp/ohhai.groovy
ohhai groovy
$ python /tmp/ohhai.sh
File "/tmp/ohhai.sh", line 2
echo ohhai bash
^
SyntaxError: invalid syntax
$ ruby /tmp/ohhai.sh
ruby: no Ruby script found in input (LoadError)
$ bash /tmp/ohhai.py
/tmp/ohhai.py: line 2: print: command not found