系统相关
首页 > 系统相关> > linux – 从不同位置执行Expect脚本

linux – 从不同位置执行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”可以提供帮助.

标签:shell,linux,automation,clearcase,expect
来源: https://codeday.me/bug/20190629/1330592.html