shell脚本+for循环
时间: 2023-11-30 20:41:36 浏览: 87
shell脚本学习(十三)——for循环语句
以下是一个简单的shell脚本+for循环的例子,它将循环变量的值赋给另一个变量,并在每次迭代中打印出来:
```shell
#!/bin/bash
for i in {1..5}
do
j=$((i+2))
echo "i is $i and j is $j"
done
```
这个脚本将循环变量i的值从1到5迭代,并将i+2的值赋给变量j。然后,它打印出i和j的值。输出如下:
```
i is 1 and j is 3
i is 2 and j is 4
i is 3 and j is 5
i is 4 and j is 6
i is 5 and j is 7
```
阅读全文