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

Avoiding Echoing

A problem with -echo is that a user may start entering a pattern that echoes but then go on to enter other characters that do not match the remainder of the pattern. The buffered characters plus the new ones will be sent to the spawned process. Assuming that the spawned process echoes them, if a pattern using -echo was causing them to echo already, the user will see characters echoed twice.

For example, in the recording script above, suppose the user enters ~q. The tilde matches and is echoed by Expect. The q does not match, so the tilde and q are sent to the spawned process and are likely echoed by the spawned process. Unfortunately, there is no trivial way to “unecho” a character without getting involved in knowing how to erase characters on the screen as well as what was on the screen in the first place. So the user ends up seeing "~~q“—one tilde too many.

There is no perfect solution for this problem except to avoid it to begin with (perhaps by not using -echo at all). But the next best possibility is to choose patterns that are less likely to match at any point unless the user is definitely entering a pattern.

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.
Start your free trial

You might also like

AI Agents in Action

AI Agents in Action

Micheal Lanham
Learning Go

Learning Go

Jon Bodner

Publisher Resources

ISBN: 9781565920903Supplemental ContentErrata Page