Getting Started With Expect

Ach Iqro
Oct 24, 2020

--

Expect is a tool for controlling interactive programs that automate interaction between user and application. Expect can save your hours of drudgery.

Expect programs are almost always written using Tcl. Tcl is a very typical looking shell like language. There are commands to set variables (set), control flow (if, foreach, while, etc.), and handle usual math and string operations. UNIX programs can be called (exec).

Expect is written after response of the specific command. The expect command describes a list of patterns to watch for. Each pattern is followed by an action. If the pattern is found, the action is executed. This is example of expect script for ssh. When executed, the script execute “ssh $username@$host”, and then it waits for the strings “*no)?”, after that it sends corresponding actions.

--

--