The Linux expect command takes script writing to an entirely new level. Instead of automating processes, it automates running and responding to other scripts. In other words, you can write a script that asks how you are and then create an expect script that both runs it and tells it that you’re ok.
Here’s the bash script:
#!/bin/bash
echo “How are you doing?”
read ans
[Get regularly scheduled insights by signing up for Network World newsletters.]
Here’s the expect script that provides the response to the query:
#!/usr/bin/expect
set timeout -1
spawn ./ask # ask is name of script to be run
expect “How are you doing?r”
send — “okr”
expect eof
When you run the script, you should see this:
To read this article in full, please click here
Source:: Network World – Linux