Getting Started With Expect

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store