Skip to Content
Exploring Expect
book

Exploring Expect

by Don Libes
December 1994
Intermediate to advanced
606 pages
16h 7m
English
O'Reilly Media, Inc.
Content preview from Exploring Expect

Telling The User About New Features

In the examples so far, the escape sequences were layered on top of the spawned process. In each case, the user must be informed of these new commands in order to take advantage of them. Indeed, the more obvious the underlying spawned process is, the more likely the user is to forget that there are extra commands available.

Printing out documentation while the program is running can be very helpful and is easy to do. The previous script showed one such example—printing out a list of choices when an escape prefix is entered. Here are some others.

The following extract is from a script that layers several commands on top of the traditional ftp client to enable it to perform recursive ftp. (Called rftp, this script comes with Expect as an example.) These new commands are entered as ~g (get recursively), ~p (put recursively), and ~l (list recursively).

puts "Once logged in, cd to the directory to be transferred and\
                                press:\n"
puts "~p to put the current directory from the local to the remote\
                                host\n"
puts "~g to get the current directory from the remote host to the\
                                local host\n"
puts "~l to list the current directory from the remote host\n"
if {[llength $argv] == 1} {
    spawn ftp
} else {
    spawn ftp [lindex $argv 1]
}

When the script starts up, it prints the messages above, which describe the new commands. Then the script drops into an interact so that ftp can enter its usual dialogue. The tilde escape works well, because ftp does not use tilde for anything ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Go

Learning Go

Jon Bodner
Command-Line Rust

Command-Line Rust

Ken Youens-Clark
Hands-on Ansible

Hands-on Ansible

Sander van Vugt

Publisher Resources

ISBN: 9781565920903Errata Page