1

我试图用来与脚本expect交谈bash,但我错过了一些东西。我的脚本是:

#!/bin/bash
echo -n "foo? "
read
echo $REPLY

我的expect脚本是:

#!/usr/bin/expect
spawn ./script.sh
expect "foo? "
send "bar\r\n"

但是bar当我运行expect脚本时我从来没有看到。我在这里想念什么?

4

2 回答 2

2

愚蠢的我,我需要添加interact到我的expect脚本中,以便它可以完成与脚本的“交互”:

#!/usr/bin/expect
spawn ./script.sh
expect "foo? "
send "bar\r\n"
interact

问完这个问题两分钟后,我在这里找到了答案。

于 2012-10-19T20:23:58.620 回答
1

我不太熟悉expect语法,但你值得一试autoexpect

autoexpect ./script.sh

它将运行script.sh,在您完成运行后,将script.exp在当前目录中创建一个期望脚本。

之后,如果您需要调整其中的某些内容,则可以对其进行编辑。

于 2012-10-19T20:24:19.960 回答