0

Assume the following bash script, questions.sh:

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

and the following expect script:

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

The expect script acts as an answering robot to the shell script. Now assume that that I need to generate some answers dynamically. For instance, let's say that I want to feed the output of another shell script (answers.sh) as an answer. How would I have to modify the expect script? I tried the following but does not seem to work:

#!/usr/bin/expect -f
spawn ./questions.sh # start our script using spawn command
expect "Hello, who are you?\r"
send ./answers.sh
2
  • You don't even need expect for this: ./answers.sh | ./questions.sh Jun 3, 2020 at 2:11
  • @glennjackman not if questions.sh has to be executed first.
    – Botond
    Jun 3, 2020 at 11:29

1 Answer 1

0

I figured it out:

#!/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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.