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

Which Spawn Id Matched

The expect command always sets expect_out(spawn_id) to the spawn id associated with the matching output. This allows a single action parameterized on its spawn id to be shared between a number of spawn ids. For efficiency reasons, the interact command does not automatically do a similar assignment. Instead, the -iwrite flag controls whether the spawn id is recorded, in this case, to interact_out(spawn_id).

The -iwrite flag should appear before each pattern to which it applies. For example, in the following fragment, action1 and action3 can access the value of interact_out(spawn_id) but action2 cannot.

interact {
    -input "$user_spawn_id $userin"
    -iwrite "foo" {action1}
            "bar" {action2}
    -iwrite "baz" {action3}
}

See Chapter 11 (p. 249) for more examples of the spawn_id element.

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