expect utility's name suggests precisely what it does: "expect" some output from an interactive program, and send the program some input in response.
expect has much more functionality than I cover in this chapter, but this chapter provides a good example of how it can be used. To find more complete information, you can consult the
expect manual page.
You may find that when you try to automate a task, the utilities or tools you are using don't lend themselves well to scripting. In the past, use of the
fdisk command (along with many others) was difficult to automate. Today we have versions of these utilities, such as
sfdisk, that are much easier to use within a script. A more modern use ...