我可以在shebang行中使用带有/ bin / env的perl的开关吗? [英] Can I use perl's switches with /bin/env in the shebang line?

查看:216
本文介绍了我可以在shebang行中使用带有/ bin / env的perl的开关吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 env 运行 perl -w 。在命令行可以正常工作:

  $ / bin / env perl -we'你好,世界!\\\
'
你好,世界!

但它不适用于脚本中的shebang行:

 #!/ bin / env perl -w 
printHello,world!\\\
;

以下是错误:

  / bin / env:perl -w:没有这样的文件或目录

显然 env 不明白我传递给 perl的 -w 。怎么了?

解决方案

hash-bang不是一个正常的shell命令行,解析和空格处理是不同的 - 你打了什么。请参阅:





基本上许多/大多数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:

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屋!

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