为 shebanged 脚本指定特定版本
如果我调用一个可执行脚本:
$ ./myscript
它在顶部有以下定义:
#! /usr/bin/env perl
并且我有以下 perls:
$ ls -l /usr/bin | grep perl
-rwxr-xr-x. 2 root root 8416 2010-07-09 05:18 perl --> perl5.10.0
-rwxr-xr-x. 2 root root 8416 2010-07-09 05:18 perl5.10.0
-rwxr-xr-x. 2 root root 8416 2010-07-09 05:18 perl4.10.0
是否可以设置某种环境变量(或任何其他方式)来表示所使用的 perl 版本将是perl4.10.0?我正在寻找一个答案,不涉及使用特定 perl 版本的绝对路径调用脚本,不更改符号链接,也不特定于语言(这意味着它适用于 /usr/bin/env ruby
、/usr/bin/env python
等)。
If I invoke an executable script:
$ ./myscript
which has the following defintion at the top:
#! /usr/bin/env perl
and I have the following perls:
$ ls -l /usr/bin | grep perl
-rwxr-xr-x. 2 root root 8416 2010-07-09 05:18 perl --> perl5.10.0
-rwxr-xr-x. 2 root root 8416 2010-07-09 05:18 perl5.10.0
-rwxr-xr-x. 2 root root 8416 2010-07-09 05:18 perl4.10.0
Is it possible to set some kind of environment variable (or any other means) to say that the perl version that is used will be perl4.10.0
? I am looking for an answer that does not involve calling the script with the absolute path to a specific perl version, doesn't change the symbolic link, nor is language specific (meaning it would work for /usr/bin/env ruby
, /usr/bin/env python
, etc).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不 - <代码>#! /usr/bin/env perl 表示“使用执行
/usr/bin/env perl
的结果作为此脚本的解释器”,因此您需要向传授额外的知识code>env
(或您选择在命令行中调用的任何其他脚本)以了解如何根据您传递的参数查找可执行文件。/usr/bin/env perl
不会在 $PATH 中查找与“perl*”匹配的文件 - 它会查找名为“perl”的可执行文件。No -
#! /usr/bin/env perl
means "use the result from executing/usr/bin/env perl
as the interpreter for this script", so you would need to impart extra knowledge toenv
(or whatever other script you chose to invoke in the command line) to know how to find executables according to the arguments you passed it./usr/bin/env perl
doesn't look in your $PATH for files matching "perl*" - it looks for an executable file named exactly 'perl'.