Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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
为什么while和do之间的公共回音线会在bash中创建死while循环?_Bash - Fatal编程技术网

为什么while和do之间的公共回音线会在bash中创建死while循环?

为什么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

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 on
while
--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的目的,一个以零退出状态退出的命令已经成功

所以你已经编好了一个无止境的循环