【发布时间】:2018-05-27 10:16:45
【问题描述】:
我通过 Expect 脚本进行 telnet,并发送一些命令并期待以下内容。
expect -re {02 : (.*?)\s}
set output $expect_out(1,string)
puts "output is $output"
=> 输出为 3(这是正确答案)
set tests "02 : "
expect -re {"$tests"(.*?)\s}
set output $expect_out(1,string)
puts "output is $output"
=> 输出为 2(其他值,该值是 $expect_out(1,string) 中用于搜索其他文本的旧值)
我可以将要搜索的文本保存在变量中并传递给expect-re {....} 吗?
我希望在变量中搜索文本,然后将该变量传递给expect..
我试过了,但是没用。
expect -re {($tests)(.*?)\s}
【问题讨论】:
-
您的直觉是正确的,我希望您能得到答案……但是 小心!!! 分段构建 RE 时必须小心。