Simple examples of Expect such as a script that needs to enter the value of a variable,
$ cat ask #! /bin/bash echo -n "Input your something:" read something echo "your input is: $something" echo "end of testing"Copy the code
How do YOU automate using this script
#! /usr/bin/expect -f set timeout -1 spawn ./ask match_max 100000 expect -exact "Input your something:" send -- "something\r" expect eofCopy the code
Expect eof indicates the end of the script
The Expect script can use Autoexpect to produce autoexpect
To use Expect in a shell, refer to the following code
#! /bin/bash echo "expect script demo" echo "The following script automatically deal with interaction" expect <<! set timeout 1 spawn ./ask expect "something" send "go demo" expect eof ! echo "expect script demo end"Copy the code