我可以在shebang行中使用带有/ bin / env的perl的开关吗? [英] Can I use perl's switches with /bin/env in the shebang line?
问题描述
我想使用 env
运行 perl -w
。在命令行可以正常工作:
$ / bin / env perl -we'你好,世界!\\\
'
你好,世界!
但它不适用于脚本中的shebang行:
#!/ bin / env perl -w
printHello,world!\\\
;
以下是错误:
/ bin / env:perl -w:没有这样的文件或目录
显然 env
不明白我传递给 perl的
。怎么了? -w
hash-bang不是一个正常的shell命令行,解析和空格处理是不同的 - 你打了什么。请参阅:
- http://www.in-ulm.de/~mascheck/various/shebang/
- http://homepages.cwi.nl/~aeb/std/hashexclam-1.html#ss1。 3
- http:// en .wikipedia.org / wiki / Shebang_(Unix)
基本上许多/大多数unix会将所有剩余的文字
$ # !/ bin / env perl -w
等效于:
/ bin / envperl -w
$ b b
,因此您需要以某种其他方式处理perl解释器的任何选项。
使用警告;
(作为@ Telemachus )
I want to run perl -w
using env
. That works fine on the command line:
$ /bin/env perl -we 'print "Hello, world!\n"'
Hello, world!
But it doesn't work on the shebang line in a script:
#!/bin/env perl -w
print "Hello, world!\n";
Here is the error:
/bin/env: perl -w: No such file or directory
Apparently env
doesn't understand the -w
flag that I'm passing to perl
. What's wrong?
The hash-bang isn't a normal shell command-line, the parsing and white-space handling is different - that's what you've hit. See:
- http://www.in-ulm.de/~mascheck/various/shebang/
- http://homepages.cwi.nl/~aeb/std/hashexclam-1.html#ss1.3
- http://en.wikipedia.org/wiki/Shebang_(Unix)
Basically many/most unixes put all of the remaining text after the first space into a single argument.
So:
#!/bin/env perl -w
is the equivalent of:
/bin/env "perl -w"
so you need to handle any options to the perl interpreter in some other fashion. i.e.
use warnings;
(as @Telemachus)
这篇关于我可以在shebang行中使用带有/ bin / env的perl的开关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!