-
The syntax of the
untilcommand is:until test-commands; do consequent-commands; doneExecute consequent-commands as long astest-commands has an exit status which is not zero. The return status is the exit status of the last command executedinconsequent-commands, or zero if none was executed.
-
The syntax of the
whilecommand is:while test-commands; do consequent-commands; doneExecute consequent-commands as long astest-commands has an exit status of zero. The return status is the exit status of the last command executedinconsequent-commands, or zero if none was executed.
-
The syntax of the
forcommand is:for name [ [in [words ...] ] ; ] do commands; doneExpand words, and executecommands once for each memberin the resultant list, with name bound to the current member. If ‘inwords’ is not present, the
forcommandexecutes thecommands once for each positional parameter that isset, as if ‘in "$@"’ had been specified. The return status is the exit status of the last command that executes. If there are no items in the expansion ofwords, no commands areexecuted, and the return status is zero.An alternate form of the
forcommand is also supported:for (( expr1 ; expr2 ; expr3 )) ; do commands ; doneFirst, the arithmetic expressionexpr1 is evaluated accordingto the rules described below . The arithmetic expressionexpr2 is then evaluated repeatedlyuntil it evaluates to zero. Each timeexpr2 evaluates to a non-zero value, commands areexecuted and the arithmetic expressionexpr3 is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command inlistthat is executed, or false if any of the expressions is invalid.
until
while
for
本文深入解析Shell编程中until、while和for三种循环命令的语法、用法及特性,帮助开发者掌握Shell循环操作的核心知识。
913

被折叠的 条评论
为什么被折叠?



