C语言中的for命令有一种特定的方法指定一个变量,就是必须保持true值用于继续失代的条件,和一种每次失代改变变量的方法。当特定的条件变为false,for循环结束!

for (i = 0; i < 10; i++)

{

   print("The next number is %d\n",i);

}

在bash中C式的for循环基本格式:

for (( variable assignment ; condition ; iteration process ))

#!/bin/bash

for (( i = 1; i <= 3; i++ ))

do

 echo "The next number is $i"

done

[root@localhost ~]# ./test8.sh 

The next number is 1

The next number is 2

The next number is 3

2.使用多个变量

#!/bin/bash

for (( a=1, b=10; a <= 5; a++, b-- ))

do

 echo "$a - $b"

done

[root@localhost ~]# ./test9.sh 

1 - 10

2 - 9

3 - 8

4 - 7

5 - 6