码迷,mamicode.com
首页 > 系统相关 > 详细

shell for循环

时间:2018-10-31 13:54:13      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:bash   str   The   div   man   bsp   Shell for   loop   comm   

 

写成一行: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次调用

 

shell for循环

标签:bash   str   The   div   man   bsp   Shell for   loop   comm   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!