【发布时间】:2019-09-29 12:18:52
【问题描述】:
我的expect 脚本很简单
#!/usr/bin/expect
set timeout 60
spawn docker run -it ubuntu:19.04
expect {
-re "root@[0-9]+:\/#"
}
send -- exit
expect eof
由于
而失败$ expect script.expect
spawn docker run -it ubuntu:19.04
invalid command name "0-9"
while executing
"0-9"
invoked from within
"expect {
-re "root@[0-9]+:\/#"
}"
(file "script.expect" line 5)
我希望这会成功,因为它是一个有效的 Perl 正则表达式,或者会失败并显示一条解释正则表达式错误的消息。似乎-re 正在尝试做其他事情而不是匹配指定的 re 这没有任何意义。
我试图逃避一切我能在 re 中猜到的东西,结果没有改变。
我在 Ubuntu 19.04 上使用 expect 5.45.4。
【问题讨论】:
-
expect不使用 Perl。 (我认为它使用 TCL?)无论如何,它看起来需要一个 POSIX 正则表达式,因为我必须切换到\[0-9\]以匹配0、1等 -
期望,作为 Tcl 扩展,会想要一个Tcl regex