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

Giving Feedback Without -echo

In practice I rarely use -echo. If the user really needs feedback, I give it immediately after recognizing that a pattern is being entered. There is no special support for this. Instead, simply use the escape prefix itself as the sole pattern and then pass control to another procedure that carries out the rest of the recognition. Here is an example from a script which uses ~~ to start commands.

interact "~~" cmd

In the cmd procedure, the user can now be directly prompted for commands:

proc cmd {} {
    send_user "command (g, p, ? for more): "
    expect_user {
        "g"        get_cmd
        "p"        put_cmd
        "?"        help_cmd
        "~"        {send "~~"}
        . . . and so on
    }
}

The user now clearly knows what they are dealing with because the prompting is very explicit. There is no way for the user to be confused about echoing because the two-tilde sequence always invokes the cmd procedure, which in turn entirely suspends the interact until the procedure returns.

Note that if the user really intended to enter two tildes and not have them interpreted as a command, another tilde has to be entered. This is a fairly standard and customary inconvenience with interactions that suspend interact commands. This style is identical to that used by the UNIX telnet command when its escape is entered.

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