Expect 中 `expect_before` 命令的用法是什么?

What's the usage of `expect_before` command in Expect?

文档说:

takes the same arguments as expect, however it returns immediately.

但是 "returns immediately" 是什么意思?

这个命令有什么用?

图像你已经产生了一个程序,比如说,随机询问 "Are you sure [yn]?"
假设这个程序有 100 个问题需要回答。

您不想有条件地期待这 100 个问题中的每个问题都有 "Are you sure" 个问题。

Expect 让你做:

spawn /some/annoying/program

expect_before {
    "Are you sure \[yn]?" {
        send "y\r"
        exp_continue
    }
}

expect "first question"
send "first answer\r"
# and so on.

现在你已经了解了:expect implicitlyexpect_before 代码添加到 each expect 命令中。