【发布时间】:2018-06-03 03:25:50
【问题描述】:
我在 bash 中浏览了 single line inifinite while loop,并尝试在带有条件的 while 循环中添加一行。下面我提到了我的命令,它给出了意想不到的结果(假设在 2 次迭代后停止,但它永远不会停止。而且它还认为变量 I 是可执行的)。
命令:
i=0; while [ $i -lt 2 ]; do echo "hi"; sleep 1; i = $i + 1; done
输出:
hi
The program 'i' is currently not installed. To run 'i' please ....
hi
The program 'i' is currently not installed. To run 'i' please ....
hi
The program 'i' is currently not installed. To run 'i' please ....
...
...
注意:我在 Ubuntu 14.04 上运行它
【问题讨论】:
-
如果您对
i的特定值进行循环,则不需要while 循环。你想要:for((i=0;i<2;i++)); do ... ; done
标签: linux bash shell while-loop