- 论坛徽章:
- 0
|
查看手册for有如下用法:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to the rules described below under ARITHMETIC EVALUATION. The arithmetic expression expr2 is then evaluated repeatedly until it evaluates to zero. Each time expr2 evaluates to a non-zero value, list is executed and the arithmetic expression expr3 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 in list that is executed, or false if any of the expressions is invalid.
但是关于上面当中说到的 每次评估expr2为非零时就执行list 有些不解
测试过:
for ((i=11;i>=3;i=i-1))
do
echo $i
done
结果:
11
10
9
8
7
6
5
4
3
for ((i=11;i;i=i-1))
do
echo $i
done
结果:
11
10
9
8
7
6
5
4
3
2
1
[ 本帖最后由 dragoncm 于 2008-11-12 20:09 编辑 ] |
|