为什么while和do之间的公共回音线会在bash中创建死while循环?
while循环将执行3次为什么while和do之间的公共回音线会在bash中创建死while循环?,bash,Bash,while循环将执行3次 i=0 while [[ $i -lt 3 ]] do echo "haha" ((i++)) done 输出: haha haha haha 让我在while和do之间添加一行echo“我在这里” i=0 while [[ $i -lt 3 ]] echo "i am here" do echo "haha" ((i++)) done 为什么它变成了一个死循环,从不停止,输出 i am here haha 永远 查看一下bash
i=0
while [[ $i -lt 3 ]]
do
echo "haha"
((i++))
done
输出:
haha
haha
haha
让我在while和do之间添加一行echo“我在这里”
i=0
while [[ $i -lt 3 ]]
echo "i am here"
do
echo "haha"
((i++))
done
为什么它变成了一个死循环,从不停止,输出
i am here
haha
永远 查看一下bash onwhile
的--help
bash.exe"-3.1$ help while
while: while COMMANDS; do COMMANDS; done
Expand and execute COMMANDS as long as the final command in the
`while' COMMANDS has an exit status of zero.
中的最后一个命令是
echo "i am here"
它将始终成功执行,因为它不会失败。
在这种情况下,退出状态为零-始终
比较
出于shell的目的,一个以零退出状态退出的命令已经成功
所以你已经编好了一个无止境的循环