bash - 为什么空循环在 shell 脚本中无效?

标签 bash shell loops

我想让我的 shell 脚本无限等待,我认为下面的代码可以做到。

#!/bin/bash
while true
do
done

但是,上面的脚本报语法错误。

./Infinite_Loop.sh: line 4: syntax error near unexpected token `done'

./Infinite_Loop.sh: line 4: `done'

与编程语言不同,为什么 shell 脚本要求循环中至少有一个语句?

最佳答案

另一种选择是设置一个 NOP(无操作),基本上什么都不做。

在 bash 中,NOP 的等价物是 :

while true; do
  :
done

关于bash - 为什么空循环在 shell 脚本中无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44970342/

相关文章:

bash - 如何配置 PATH 变量以便我可以在 CLI 上运行包?

bash - 如何在不使用文件实用程序的情况下判断文件是否为文本文件?

bash - Shell 重定向 i/o 顺序

bash - Bash脚本: 'Syntax error: “fi” unexpected' within nested statement

php - 主页模板循环自定义 - 应根据帖子模板获取内容

android - 如何从字符串数组中随机获取文本?

linux - bash 中的 unix 历史命令 "!$"是什么?

linux - 强制 rsync 逐字节比较本地文件而不是校验和

linux - 如何从父进程获取子进程

java - Do/While Loop 当条件设置为 false 时循环