bash - 期望脚本调用 bash 脚本,输出可能不会发生
问题描述
我正在尝试编写一个调用 bash 脚本的期望脚本,该脚本可能会也可能不会输出一行文本:
...
expect "this string appears"
...
expect "this string may or may not appear"
...
expect "this string appears"
...
如果出现“这个字符串可能出现也可能不出现”,或者如果没有出现,我该如何编写代码来发送一些东西?
解决方案
您将使用多模式期望语句:
expect {
"this string may or may not appear" {
# do stuff ...
exp_continue
}
"this string appears"
}
# ... do more stuff
该exp_continue
命令本质上是在 expect 命令中“循环”,因此它可以继续寻找任何给定的模式。最后一个模式“这个字符串出现”没有动作块,所以expect命令返回并且脚本继续执行下一个命令。
推荐阅读
- flutter - Iconbutton onPress no 在颤动中调用
- javascript - Kotlin 的 null 感知运算符“?:”是否有“直接分配”?
- android - 如何在 Rollette 游戏中向每个部分跨 android 播放声音
- python - 添加自定义类小部件时 PanedWindow 没有子级
- numpy - 使用 numpy 进行 numba 编译有什么问题?
- javascript - 函数未正确完成其任务
- javascript - DataTables.net 中分页、长度更改和信息控件的定位
- amazon-web-services - 如何在 AWS 中 ping 同一 vpc 相同子网但不同安全组中运行的 EC2 实例
- botframework - 用于 Botframework 的 Azure Active Directory
- puppet - puppet-master控制puppet-client的时候,可以不用证书配置吗?