find2perl perl shebang + eval的确切含义是什么? [英] What is the exact meaning of the find2perl perl shebang + eval?
问题描述
以下内容有什么作用?
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
-
if 0
永远不会为真,因此eval部分将永远不会执行, - 并且评估也很奇怪-在这种情况下,
$0
的值是什么(在单引号内?) - the
if 0
is never true, so the eval part will never executed, - and the eval is strange too - what is the value of
$0
in this context (inside single quotes?)
Ps:取自find2perl命令的结果
Ps: taken from the result of the find2perl command
推荐答案
最佳猜测-如此注释#$running_under_some_shell
所示,它用于检测脚本是否由除perl之外的其他shell运行,例如重击.
Best guess - as in this comment #$running_under_some_shell
, it's to detect if the script is being run by some shell other than perl, e.g. bash.
如果0永远都不为真,那么评估部分将永远不会执行,
the if 0 is never true, so the eval part will never executed,
不是perl,不是.对于其他shell(例如bash),它不会发现行继续,而只会执行eval
语句.然后,这将在perl下重新运行该脚本. (奇怪的是,它的选项与hashbang行不同.)
Not by perl, no. By other shells such as bash it won't spot the line continuation and will just execute the eval
statement. This then re-runs the script under perl. (Oddly with different options than the hashbang line.)
并且eval也很奇怪-在这种情况下,$ 0的值是多少(在单引号内?)
and the eval is strange too - what is the value of $0 in this context (inside single quotes?)
同样,它将通过bash而不是perl进行扩展:这意味着find2perl传递到perl解释器中的路径.
Again, this will be expanded by bash not perl: here it means the path to find2perl to pass into the perl interpreter.
这篇关于find2perl perl shebang + eval的确切含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!