- 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.
untilwhilefor
本文详细介绍了Shell脚本中的三种循环结构:until、while和for循环的语法及使用方法,并解释了它们的执行逻辑和返回状态。此外,还特别说明了for循环的一种替代形式及其算术表达式的评估规则。
919

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



