shell-for循环

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

 

posted @ 2016-12-28 10:24  243573295  阅读(240)  评论(0编辑  收藏  举报