什么意思是“不在某些外壳下运行”?在Perl脚本中? [英] What means "not running under some shell" in Perl scripts?

查看:78
本文介绍了什么意思是“不在某些外壳下运行”?在Perl脚本中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多perl脚本中(尤其是在著名的CPAN发行版中),我发现以下代码:

In many perl scripts (especially in famous CPAN distros) I find the following piece of code:

eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell

我想知道它的用途是什么?

I was wondering what it is for?

谢谢。

推荐答案

某些系统无法识别#! / usr / bin / perl 脚本开头的行,因此,在这样的系统上尝试通过名称调用Perl程序会将脚本传递给shell。为了解决这个问题,可移植的Perl程序以一行开头,当由标准POSIX shell解释时,该行将脚本传递给 perl(1) if 0 导致当由Perl本身运行时该行被忽略,而将其放在单独的行上会使Shell将其视为单独的命令,仅运行 eval'exec / usr / bin / perl -w -S $ 0 $ {1 + $ @}''一旦被读取。

Some systems don't recognize the #!/usr/bin/perl line at the start of scripts, and so trying to invoke a Perl program by name on such a system will simply pass the script to the shell. In order to combat this, portable Perl programs begin with a line that, when interpreted by a standard POSIX shell, causes the script to be passed to perl(1) instead. The if 0 causes the line to be ignored when run by Perl itself, and placing it on a separate line causes shells to treat it as a separate command, running just the eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' as soon as it's read.

这篇关于什么意思是“不在某些外壳下运行”?在Perl脚本中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆