sheel语言for循环格式
for var in item1 item2 ... itemN do command1 command2 ... commandN done
案例1
#!/bin/bash for v in 1 2 3 4 5 do echo "The value is: $v" done
输出
The value is: 1 The value is: 2 The value is: 3 The value is: 4 The value is: 5
案例2,与数组配合
#!/bin/bash datatime=(1 2 3 4 5) echo ${datatime[0]} for v in ${datatime[@]} do echo "The value is: $v" done