如何在“期望脚本”中启动Shell脚本?

use*_*706 4 expect

在此期望脚本中,将没有ssh服务器连接,我只想在本地执行“ .sh”文件,这可能吗?

例如:

#!/bin/expect

command "xxx.sh" # a command which starts a certain shell script
Run Code Online (Sandbox Code Playgroud)

另外,是否可以在期望脚本中执行期望脚本?

例如:

#!/bin/expect

command "xxx.exp" # a command which starts a certain expect script
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?

Bar*_*mar 5

运行 shell 命令的 Expect 中的命令是spawn.

#!/bin/expect
spawn command arg1 arg2 ...
Run Code Online (Sandbox Code Playgroud)

command 可以是任何程序——二进制可执行文件、shell 脚本、另一个期望脚本等。所以你可以这样做:

spawn xxx.sh
Run Code Online (Sandbox Code Playgroud)

或者:

spawn xxx.exp
Run Code Online (Sandbox Code Playgroud)


gle*_*man 5

如果您需要与此脚本进行交互,请使用spawn xxx.sh

如果只需要运行它并捕获输出,请使用 set output [exec xxx.sh]

Expect是Tcl语言的扩展,因此您将很高兴阅读Tcl教程