linux - 期望工具和逻辑或
问题描述
我对我的脚本使用expect
命令。我有几个不同的提示,我需要 OR 来表示表达式。
有可能做这样的事情吗?
expect {
'Hello. Press y for YES' *OR* 'Welcome again. Press y' {send -- "y\r" }
}
解决方案
期望已经具有或内置,例如:
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"}