shell--循环语句

2021-09-12, updated 2021-09-20

for语句

顺序输出当前列表中的数字:

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

顺序输出字符串中的字符:

#!/bin/bash

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

输出结果

This
is
a
string
words: 89 tags: shell