我想让我的 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/