首页 > 解决方案 > 期望工具和逻辑或

问题描述

我对我的脚本使用expect命令。我有几个不同的提示,我需要 OR 来表示表达式。

有可能做这样的事情吗?

expect {
   'Hello. Press y for YES' *OR* 'Welcome again. Press y' {send -- "y\r" }
}

标签: linuxexpect

解决方案


期望已经具有内置,例如:

expect {
  "Hello. Press y for YES"  {send -- "y\r"}
  "Welcome again. Press y"  {send -- "y\r"}
}

如果动作太大,你可以把它放在一个函数中。但是,如果您愿意,可以使用正则表达式a|b

expect -re "Hello. Press y for YES|Welcome again. Press y"  {send "y\r"}

推荐阅读