1.for语句的格式
for NUM in 1 2 3
for NUM in {1…3}
for NUM in seq 1 3 或者
for NUM in seq 1 2 10 do done
2.for语句的实例
1 2 3 4 5 6 7
| 1#!/bin/bash
2for i(变量的名字) in {1..10}(变量的范围)
3do
4 echo $i(输出变量i的所有值)
5done
6
7 |
1 2 3 4 5 6 7 8 9
| 1#!/bin/bash
2a=1
3b=10
4for i in {$a..$b}
5do
6 echo $i
7done
8
9 |
注:这样输出的结果为:{1…10}
1 2 3 4 5 6 7 8 9
| 1#!/bin/bash
2a=1
3b=10
4for i in `seq $a $b`
5do
6 echo $i
7done
8
9 |
输出结果为:
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7
| 1#!/bin/bash
2for i in tom haha lee
3do
4 echo $i
5done
6
7 |
1 2 3 4 5 6 7
| 1#!/bin/bash
2for ((i=1;i<10;i++))
3do
4 echo $i
5done
6
7 |