加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – Bash Shell Do While Loop Infinite循环?

发布时间:2020-12-14 01:27:29 所属栏目:Linux 来源:网络整理
导读:基本上这是我的代码: bay=$(prog -some flags)while [ $bay = "Another instance of this program is running,please exit it first" ]doecho "Awaiting Access to program"do..... 我有一个程序,它只允许一个实例一次运行,因为它与我的硬件交互的方式,当另
基本上这是我的代码:

bay=$(prog -some flags)
while [ $bay = "Another instance of this program is running,please exit it first" ]
do
echo "Awaiting Access to program"
do
.....

我有一个程序,它只允许一个实例一次运行,因为它与我的硬件交互的方式,当另一个实例运行时它踢出以下消息“该程序的另一个实例正在运行,请先退出它” .

我需要能够运行多个脚本,这将使用相同的程序,所以我决定使用上面的代码.我的问题是,当我运行我的两个脚本时,一个人将获得对程序的访问并按照需要运行,但另一个将注意到错误,然后卡在一个无限循环中,回显“等待访问程序”.

错过了什么? Statement是执行CLI命令还是只是重新执行其原始执行?或者我的问题在哪里?

解决方法

您没有在某个地方更新循环内的bay变量.它被设置一次并保持不变.你需要每次都重新计算它.

在循环内设置托架,或者在while的条件下设置托架.

while [ `prog -some flags` = "Another instance of this program is running,please exit it first" ]

编辑:

从您的评论中,您希望以后能够引用此输出.你可以回到你拥有的东西,但是在你的阻塞循环中,把你的bay = $(prog -some flags)命令放在循环中.它会留在你身边供你使用.

bay=$(prog -some flags)
while [ $bay = "Another instance of this program is running,please exit it first" ]
do
echo "Awaiting Access to program"
bay=$(prog -some flags)
done
.....

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读