Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux bashshell执行While循环无限循环?_Linux_Bash_Shell_While Loop_Do While - Fatal编程技术网

Linux bashshell执行While循环无限循环?

Linux bashshell执行While循环无限循环?,linux,bash,shell,while-loop,do-while,Linux,Bash,Shell,While Loop,Do While,基本上这是我的代码: bay=$(prog -some flags) while [ $bay = "Another instance of this program is running, please exit it first" ] do echo "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
.....
我有一个程序,由于它与我的硬件交互的方式,一次只允许运行一个实例,当另一个实例运行时,它会弹出以下消息“此程序的另一个实例正在运行,请先退出”

我需要能够运行多个脚本,这将使用相同的程序,所以我决定使用上述代码。我的问题是,当我运行我的两个脚本时,其中一个将获得对程序的访问权并按需要运行,但另一个将注意到错误,然后陷入一个内联循环,回显“等待访问程序”


你错过了什么?该语句是在执行CLI命令,还是只是返回其原始执行?或者我的问题在哪里?

您没有更新循环中某个地方的
变量。它设置一次并保持不变。每次都需要重新计算

在循环内或在while条件下设置
bay

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
.....
更多,我会等待用户先做一些事情,而不是敲打prog:

while true
do
  bay=$(prog -some flags)
  case "$bay" in
    "Another instance of this program is running, please exit it first")
      read -p "Awaiting Access to program. Close it and hit enter: " x ;;
    *) break ;;
  esac
done
echo "Results: $bay"

在后面的If-Else语句中是否有调用变量的方法?还是我应该开始一个新的变量?我更新了我的回复,以便在您的新需求中提供建议。