Closed Captioning Closed captioning available on our YouTube channel

How to use expect: 2-Minute Linux Tips

Network World | Jan 22, 2021

In this Linux tip, learn how to use expect. It's a tool that allows you to automate interactions with other scripts so that you can run them with a set of predefined answers.

Copyright © 2021 IDG Communications, Inc.

Similar
Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at expect. It's a tool that allows you to automate interactions with other scripts so that you can run them with a set of predefined answers. For a super simple example, say you have a script called ask00 that looks like this:
Now you want another script to run it for you and tell it you're OK, so you prepare a script that looks like this one:
We can see that this script is run by expect. It spawns the ask00 script and anticipates the question that it will ask. It then provides the answer you set up ahead of time.
When you run the expect script, you'll see something like this:
All you had to do was type "exp00".
Of course, in the real world, rather than in the confines of a 2-minute video, the script you're running will likely ask a lot more questions and do some real work. You can provide as many expect and send lines in your script as are needed to get the job done.
That’s your Linux tip for expect.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.

Popular
Featured videos from IDG.tv