1

I try to do the following in a shell script:

bash;

in the bash context:

  • run ./a.out

And In ./a.out context I need to simulate keystorkes:

yes
3292
no

How can I do it? All my tries failed since &, && and ; executes the subsequent command in the main shell context and not in the bash.

bash && echo "yes" > /dev/console

I have seen use expect in shell script aren't there any alternative using native shell commands ? I don't want to be dependent on other tools.

1 Answer 1

2

Take a look into expect, which "talks" to interactive programs with the help of a user provided script.

Usage

expect ./interact

or making interact executable (chmod a+x interact):

./interact

where interact is the following script:

#!/usr/bin/expect
spawn ./a.out
send -- "yes\r"
expect "3292\r"
send -- "no\r"

This is just a simple example, the man page is full of in depth explanations and there are also example scripts which come with the installation.

References

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.