expect_out(0,string) //变量存储匹配到的字符
expect_out(buffer) //变量存储匹配到的字符加上之前出现的字符
测试脚本:
expect "hi\n"
send "you typed <$expect_out(buffer)>"
send "but I only expected <$expect_out(0,string)>"
//匹配之后,后续匹配从新数据开始
expect "hi"
send "$expect_out(0,string) $expect_out(buffer)"
expect "hi"
send "$expect_out(0,string) $expect_out(buffer)"
结果:
philosophic
hi phihi losophi
//匹配多种情况,匹配到其中一个即执行
expect "hi" { send "You said hi\n" } \
"hello" { send "Hello yourself\n" } \
"bye" { send "That was unexpected\n" }
//多种匹配的另一种写法
expect {
"hi" { send "You said hi\n"}
"hello" { send "Hello yourself\n"}
"bye" { send "That was unexpected\n"}
}