Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以使用perl';在shebang线中使用/bin/env的s开关?_Perl_Command Line_Scripting_System - Fatal编程技术网

我可以使用perl';在shebang线中使用/bin/env的s开关?

我可以使用perl';在shebang线中使用/bin/env的s开关?,perl,command-line,scripting,system,Perl,Command Line,Scripting,System,我想使用env运行perl-w。这在命令行上运行良好: 但它在脚本中的shebang行上不起作用: #!/bin/env perl -w print "Hello, world!\n"; 以下是错误: /bin/env: perl -w: No such file or directory 显然env不理解我传递给perl的-w标志。怎么了 而不是-w使用警告pragma(对于现代版本的Perl): hash-bang不是一个普通的shell命令行,解析和空白处理是不同的——这就是您所遇到的

我想使用
env
运行
perl-w
。这在命令行上运行良好:

但它在脚本中的shebang行上不起作用:

#!/bin/env perl -w
print "Hello, world!\n";
以下是错误:

/bin/env: perl -w: No such file or directory

显然
env
不理解我传递给
perl
-w
标志。怎么了

而不是
-w
使用警告pragma(对于现代版本的Perl):


hash-bang不是一个普通的shell命令行,解析和空白处理是不同的——这就是您所遇到的。见:

基本上,许多/大多数Unix将第一个空格后的所有剩余文本放入一个参数中

因此:

相当于:

/bin/env "perl -w"
因此,您需要以其他方式处理perl解释器的任何选项。i、 e

use warnings;

(as@)

我认为提出“-w”与“使用警告”不同可能会有用-w将适用于您使用的所有软件包,“使用警告”仅在词汇上适用。您通常不想使用或依赖“-w”

值得注意的是,Mac OS X将shebang后面的字符解释为参数,因此在OS X上,以下操作将起作用:

#!/usr/bin/env perl -wT
enter code here

然而,因为使用#的要点之一/usr/bin/env是为了促进跨平台兼容性,最好不要使用这种语法,即使您主要使用的是Mac

是的,我知道“使用警告”,但我习惯于只写“perl-w”,我不知道“env”可以在命令行中工作,但不能在脚本中工作。“perl-w”可以在Unix上工作,更简洁,但不能在Windows上工作(除非ActivePerl或其他什么东西在shebang行中显式查找命令行标志),因此,最好只是“使用警告;”。还可以看看如何使用一些shell黑客和。
/bin/env "perl -w"
use warnings;
#!/usr/bin/env perl -wT
enter code here