什么“while :; do”真的在bash中做什么?

时间:2012-05-06 00:23:20

标签: bash

我看到这样的代码:

while :; do
    #commands
done

相同
while :
do
    #commands
done

这只是一个无限循环吗?

2 个答案:

答案 0 :(得分:2)

:是内置Null command的shell。您可以在终端中输入help :

:: :
    Null command.

    No effect; the command does nothing.

    Exit Status:
    Always succeeds.

看起来像/bin/true

答案 1 :(得分:1)

是的,这只是一个无限循环。您通常会发现while循环内的代码调用break以在满足某些条件时退出循环。