shell for循环

写成一行:for var in item1 item2 ... itemN; do command1; command2 done;

#顺序输出

for loop in 1 2 3 4 5
do
    echo "The value is: $loop"
done

结果输出

The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5

#输出字符串中的字符

for str in 'This is a string'
do
    echo $str
done

结果输出

This is a string

例:

#!/bin/bash
for((i=1;i<=5;i++));do
    echo "这是第 $i 次调用";
done;

结果输出:

这是第1次调用
这是第2次调用
这是第3次调用
这是第4次调用
这是第5次调用

原文地址:https://www.cnblogs.com/sea-stream/p/9882252.html