期待来自 bash 的动态输入

期待来自 bash 的动态输入

假设以下bash脚本questions.sh

#!/bin/bash
echo "Hello, who are you?"
read REPLY

和以下expect脚本:

#!/usr/bin/expect -f
spawn ./questions.sh # start our script using spawn command
expect "Hello, who are you?\r"
send -- "Im Adam\r"

Expect 脚本充当 shell 脚本的应答机器人。现在假设我需要动态生成一些答案。例如,假设我想提供另一个 shell 脚本 ( answers.sh) 的输出作为答案。我该如何修改expect脚本?我尝试了以下方法,但似乎不起作用:

#!/usr/bin/expect -f
spawn ./questions.sh # start our script using spawn command
expect "Hello, who are you?\r"
send ./answers.sh

答案1

我想到了:

#!/usr/bin/expect -f
spawn ./questions.sh # start our script using spawn command
expect "Hello, who are you?\r"
set answer [exec ./answer.sh]
send $answer

相关内容