shell编程中while true 中的true是bash的内置命令还是/bin/true呢? 1)运行bash,确保是bash环境 2)下面看看相关命令的帮助。 运行 help true,你会看到: $ help true true: true Return a successful result. Exit Status: Always succeeds. true是bash的内置命令,总返回成功(退出状态总是0)。 3)运行 help : ,你会看到: $ help : :: : Null command. No effect; the command does nothing. Exit Status: Always succeeds. 冒号 : 是bash的内置命令,也叫空命令,也叫null命令,总返回成功(退出状态总是0)。 4)运行 help while ,你会看到: $ help while while: while COMMANDS; do COMMANDS; done Execute commands as long as a test succeeds. Expand and execute COMMANDS as long as the final command in the `while' COMMANDS has an exit status of zero. Exit Status: Returns the status of the last command executed. while 是bash的内置命令,while后面的命令成功(退出状态是0)时,do 和done之间的命令就会执行,即,do 和done之间的东西就会循环。 所以说 while true与while :确实等同。类似于C语言中的 while (1),用于构造无穷循环。 |
|