How To Read This Book

This book can be read from front to back. Each chapter flows naturally into the next, and examples in each chapter only use the concepts that have been introduced up to that point. Of course, you can skip chapters or jump around if you like. But I recommend you come back and read everything eventually. This book is chock-full of examples—and they are really worth seeing. To further stimulate you, exercises at the end of each chapter hint at additional thoughts and applications.

Expect draws together a lot of concepts from different programs and even different operating systems. For this reason it is likely that you are familiar with some pieces but not others. The book is laid out so that it is easy to skip things with which you are already familiar. The Preface provides mostly historical notes, setting the scene for Expect and describing how it came into existence. This is not critical to the use of Expect but it makes interesting reading. You may want to read it later.

Chapter 1 is an overview of Expect, giving a taste of what it can do, why it is worth your attention, who uses it, and how it fits into the world. If you know little or nothing about Expect and would like to quickly know what it is all about, read this chapter rather than flipping through the book.

Chapter 2 is an overview of Tcl, the language that Expect uses. Tcl is used by many other software packages so you may already know it—I encourage you to read Chapter 2 anyway. Even if you know Tcl already, you will find that aspects of the language that Expect relies upon are different than in other Tcl tools. Chapter 2 emphasizes these aspects and at the same time puts the rest of Tcl into a consistent framework so that it all fits together.

After Chapter 2 comes the meat of the book—chapters that focus on different parts of Expect starting with automating simple interactions and ending with sophisticated and complex applications that use multiple processes and graphic front-ends. The chapter names are suggestive of the main concepts covered in each chapter; however, all of the chapters include many other concepts that are easier to explain in the context of the chapters they are in. This makes the titles a little less helpful, but the Extended Table Of Contents lists all of the concept headings of each chapter.

Near the end of the book are several chapters on subjects that may not be of interest to everyone. For instance, one such chapter is how to use Expect with Tk; another is how to use Expect from C or C++ (without Tcl). There is also a chapter on embedding Expect in with your own Tcl extensions. That particular chapter assumes that you have read the Tcl reference documentation on the C interface.

The last chapter contains some topics that did not deserve their own chapters nor did they fit in any others. The concepts there are not that important but may be useful nonetheless.

I believe strongly in thorough indexes and there are two in this book so that you can find any item even if it is not in the Extended Table of Contents. The primary index cross-references all concepts, commands, examples, and figures. Many of the examples in the book are interesting in their own right and you will want to use them as tools on their own. In order to find your way back to them, another index lists the substantive examples. Most of these are also available in machine-readable form with the Expect distribution itself. I will describe how to obtain the distribution in Chapter 1 (p. 16)

There is also an appendix that contains a list of all of the Expect commands and variables. Each entry has a brief description and a page number back to the body of the book where you can get the full explanation. I recommend you turn to page 525 and dog-ear it right now!

Most of the chapters are heavily illustrated with code fragments. Code-reading is essential to see how things look in context. And the more code to which you are exposed, the more ideas you can learn. It is also important to see larger pieces of code, and I have provided several significantly bigger programs in chapters towards the rear of the book. Unlike most programs found in the Tcl archives, the ones in this book are extensively and carefully described.

Finally, a gentle warning before you start reading—this book describes how to use Expect, but it is not a reference manual. While terse and lacking in background and examples, the man page that comes with the Expect software is always the latest and most accurate documentation. If Expect changes, it will be reflected there.

Notational Conventions

Body text is set in ITC Garamond Light. Terms being defined or emphasized are italicized. Parameterized input or output (i.e., rmfilename) appears as Courier Italic. Courier is used for source code, files, hostnames, literal I/O, or anything that is computer input or output. Characters typed by a person are in Courier Bold. Due to the nature of Expect, it may sometimes appear that a person has typed something when in reality it was typed by Expect. Thus, the boldness of the font will be helpful in these otherwise misleading situations.

Straight quotes (' or " or ') are used when they are literally part of the characters or strings. Curly quotes (“”) are occasionally used to distinguish literal text from the surrounding text or nearby punctuation if it might not otherwise be obvious (or for consistency with other strings in the same sentence).

Inter-chapter references such as "Chapter 1 (p. 19)” include page numbers describing exactly where in the chapter the referenced topic appears. In this example, the discussion of Expect and Tcl resources appears in the first chapter and the discussion itself begins on page 19.

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.