第一类:数字性循环
-----------------------------
for1-1.sh

#!/bin/bash  

for((i=;i<=;i++));
do
echo $(expr $i \* + );
done

-----------------------------
for1-2.sh

#!/bin/bash  

for i in $(seq  )
do
echo $(expr $i \* + );
done  

-----------------------------
for1-3.sh

#!/bin/bash  

for i in {..}
do
echo $(expr $i \* + );
done

-----------------------------
for1-4.sh

#!/bin/bash  

awk 'BEGIN{for(i=1; i<=10; i++) print i}'  

第二类:字符性循环
-----------------------------
for2-1.sh

#!/bin/bash  

for i in `ls`;
do
echo $i is file name\! ;
done  

-----------------------------
for2-2.sh

#!/bin/bash  

for i in $* ;
do
echo $i is input chart\! ;
done

-----------------------------
for2-3.sh

#!/bin/bash  

for i in f1 f2 f3 ;
do
echo $i is appoint ;
done

-----------------------------
for2-4.sh

#!/bin/bash  

list="rootfs usr data data2"
for i in $list;
do
echo $i is appoint ;
done

第三类:路径查找
-----------------------------
for3-1.sh

#!/bin/bash  

for file in /proc/*;
do
echo $file is file path \! ;
done

-----------------------------
for3-2.sh

#!/bin/bash  

for file in $(ls *.sh)
do
echo $file is file path \! ;
done

总结:

现在一般都使用for in结构,for in结构后面可以使用函数来构造范围,比如$()、``这些,里面写一些查找的语法,比如ls test*,那么遍历之后就是输出文件名了。

参考:

http://blog.csdn.net/babyfish13/article/details/52981110(以上内容转自此篇文章)

Linux下Shell的for循环语句的更多相关文章

  1. Linux - 简明Shell编程06 - 循环语句(Loop)

    脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash # for循环 for fil ...

  2. Linux 下Shell的学习

    1.Shell学习 1.什么是Shell    shell是一个命令解析器,在操作系统的最外层,负责和用户对话,将用户的输入解释给操作系统,并处理各种各样的操作系统的输出结果.2.什么是shell脚本 ...

  3. Linux 下shell 编程学习脚手架

    linux body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-t ...

  4. shell脚本之循环语句与函数

    shell脚本之循环语句与函数 echo的用法: echo -n #表示不换行输出 echo -e #输出转义字符,将转义后的内容输出到屏幕上 转义字符: \n :换行,被输出的字符从"\n ...

  5. Shell编程之循环语句与echo的用法

    Shell编程之循环语句与echo的用法 目录 Shell编程之循环语句与echo的用法 一.echo用法 1. echo常用选项 2. 常用的转义字符 3. 特殊符号%.#的用法 二.循环语句 1. ...

  6. 06 Linux下Shell介绍

    一.概述 每个人在成功登陆Linux后,系统会出现不同的提示符号,例如$,~,#等,然后你就可以开始输入需要的命令.若命令正确,系统就会依据命令的要求来执行,直到注销系统为止,在登陆到注销期间,输入的 ...

  7. .Neter玩转Linux系列之四:Linux下shell介绍以及TCP、IP基础

    基础篇 .Neter玩转Linux系列之一:初识Linux .Neter玩转Linux系列之二:Linux下的文件目录及文件目录的权限 .Neter玩转Linux系列之三:Linux下的分区讲解 .N ...

  8. Linux 下Shell变量,环境变量的联系与区别

    Linux下Shell变量,环境变量的联系与区别 by:授客 QQ:1033553122 1.  简介 linux下的变量可分成两种:Shell变量和环境变量. Shell变量,又称本地变量,包括私有 ...

  9. Linux下Shell元字符的释义

    Linux下shell的巧妙应用,对系统的运维很有四两拨千斤的功效! Shell元字符 注意: () 在当前shell的子shell进程运行命令 {}在当前shell进程运行命令

随机推荐

  1. N - Asteroids

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  2. 最大团&优化

    貌似咕了三个半月了(gym101915里一道),今天又遇到一道(cf1105E),就学了学惹. 最大团定义:图上取尽可能多的点,这些点构成一个完全图. 最大独立集:图上取尽可能多的点,任意两点间不连接 ...

  3. 【2】static 、construct

    [面向对象] 两个概念: 什么是类 具有一批相同属性的集合 什么是对象 特指的某一个具体的事物 [面向对象的三大特征] 1.封装 public 公共的 protected 受保护的 private 私 ...

  4. rails 杂记 - render and layout

    官方文档:http://guides.rubyonrails.org/layouts_and_rendering.html 渲染 view 渲染 html.rb 与相应的 action control ...

  5. 21、bootstrap框架

    http://www.bootcss.com/ Bootstrap 插件==全部依赖 jQuery== 请注意,Bootstrap 的所有 JavaScript 插件都依赖 jQuery,因此 jQu ...

  6. HttpRequest获得服务端和客户端的详细信息

    参考文档:http://blog.csdn.net/u012104100/article/details/43051301 http://blog.csdn.net/u011162260/articl ...

  7. Sring 类的例子

    public class ZongHe {     public static void main(String[] args) {     function1();            funct ...

  8. ASP返回JQuery EasyUI树形要求的JSON格式

    根据http://blog.csdn.net/apollokk/article/details/41382479中提供的数据将结果格式化为JQuery EasyUI树形要求的JSON格式 <% ...

  9. python扫描端口脚本

    # -*- coding:utf8 -*- # # Python: 2.7.8 # Platform: Windows # Authro: wucl # Program: 端口扫描 # History ...

  10. MySQL 添加索引,删除索引及其用法

    一.索引的作用 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,所以查询语句的优化显然是重中之重. 在数据 ...