加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 从不同位置执行Expect脚本

发布时间:2020-12-13 22:53:46 所属栏目:Linux 来源:网络整理
导读:我试图从两个不同的位置运行我的Expect脚本,它将使用引用的以下Expect可执行文件: 我的linux主目录(#!/usr/bin/expect) 另一台服务器上的清晰视图(#!/ clearlib / vobs / otherdir / bin / expect) 问题是我无法在两个地方运行脚本,除非我将Expect可执行
我试图从两个不同的位置运行我的Expect脚本,它将使用引用的以下Expect可执行文件:

>我的linux主目录(#!/usr/bin/expect)
>另一台服务器上的清晰视图(#!/ clearlib / vobs / otherdir / bin / expect)

问题是我无法在两个地方运行脚本,除非我将Expect可执行文件位置的引用更改为文件的第一行.

如何获取相应目录的Expect可执行文件的正确实例?

解决方法

如果在两台服务器上正确设置了路径,则可以使用 /usr/bin/env

#!/usr/bin/env expect

这将使用在PATH中找到的expect(在一种情况下为/usr/bin,在另一种情况下为/ clearlib / vobs / otherdir / bin)

By instead using env as in the example,the interpreter is searched for and located at the time the script is run.
This makes the script more portable,but also increases the risk that the wrong interpreter is selected because it searches for a match in every directory on the executable search path.
It also suffers from the same problem in that the path to the env binary may also be different on a per-machine basis.

如果您在设置正确的PATH时遇到问题,那么“/usr/bin/env questions regarding shebang line pecularities”可以提供帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读