shell编程:for 循环
hell 编程——for in 循环
- for 无$变量 in 字符串
- do
- $变量
- done
- SERVICES="80 22 25 110 8000 23 20 21 3306 "
- for x in $SERVICES
- do
- iptables -A INPUT -p tcp --dport $x -m state --state NEW -j ACCEPT
- done
- #!/bin/sh
- for i in a b c 字符串列表A B C
- 字符串用空格分隔,没有括号,没有逗号, 然后循环将其依次赋给变量i
- 变量没有$
- do
- echo "i is $i"
- done
- #!/bin/bash
- for i in *.h ;
- do
- cat ${i}.h
- done
- #!/bin/bash
- for i in *.h
- do
- cat $i
- done
- for i in /etc/profile.d/*.sh
- do
- $i
- done
- test()
- {
- local i
- for i in $* ; do
- echo "i is $i"
- done
- }
- for i in *.txt *.txt相当于一个字符串数组,依次循环赋值给i
- do
- mv "$i" "$i.bak"
- done
- for i in $(ls *.txt)
- do
- echo $i
- done
- LIST="rootfs usr data data2"
- for d in $LIST; do
- mount /backup/$d
- rsync -ax --exclude fstab --delete /$d/ /backup/$d/
- umount /backup/$d
- done
- for((i=1;i<=10;i++));do echo $(expr $i \* 4);done
- 在shell中常用的是 for i in $(seq 10)
- for i in `ls`
- for i in ${arr[@]}
- for i in $* ; do
- for File in /proc/sys/net/ipv4/conf/*/accept_redirects; do
- for i in f1 f2 f3 ;do
- for i in *.txt
- for i in $(ls *.txt)
- LIST="rootfs usr data data2"
- for d in $LIST; do
- 用for in语句自动对字符串按空格遍历的特性,对多个目录遍历
- for i in {1..10}
- for i in stringchar {1..10}
- awk 'BEGIN{for(i=1; i<=10; i++) print i}'
- #/bin/bash
- # author: 周海汉
- # date :2010.3.25
- # blog.csdn.net/ablo_zhou
- arr=("a" "b" "c")
- echo "arr is (${arr[@]})"
- echo "item in array:"
- for i in ${arr[@]}
- do
- echo "$i"
- done
- echo "参数,\$*表示脚本输入的所有参数:"
- for i in $* ; do
- echo $i
- done
- echo
- echo '处理文件 /proc/sys/net/ipv4/conf/*/accept_redirects:'
- for File in /proc/sys/net/ipv4/conf/*/accept_redirects; do
- echo $File
- done
- echo "直接指定循环内容"
- for i in f1 f2 f3 ;do
- echo $i
- done
- echo
- echo "C 语法for 循环:"
- for (( i=0; i<10; i++)); do
- echo $i
- done
- #!/bin/bash
- clear
- for((i=1;i<100;i++))
- for
- do
- if((i%3==0))
- then
- echo $i
- continue
- fi
- done
- #!/bin/bash
- clear
- for i in `seq 100`
- do
- if((i%3==0))
- then
- echo $i
- continue
- fi
- done
- #!/bin/bash
- clear
- i=1
- while(($i<100))
- do
- if(($i%3==0))
- then
- echo $i
- fi
- i=$(($i+1))
- done
- for i in `seq 1 1000000`;do
- echo $i
- done
- for((i=1;i<10000000;i++));do
- echo $i
- done
- i=1
- while(($i<10000000));do
- echo $i
- i=`expr $i + 1`
- done
- for i in {1..10000000;do
- echo $i
- done
- #!/bin/bash
- D=`date +%Y%m%d`
- for A in `ls | grep $D`
- do
- echo "$A"
shell编程:for 循环的更多相关文章
- 04 shell编程之循环语句
Shell编程之循环语句 学习目标: 掌握for循环语句编程 掌握while循环语句编程 目录结构: For循环语句 l 读取不同的变量值,以逐个执行同一组命令 l For语句结构 for 变量名 ...
- shell编程之循环语句for / while / until
shell编程之循环语句与函数 一.条件测试 二.循环语句 ① for循环语句结构(遍历) 示例1 示例2 ② while循环语句结构(迭代) 示例1 示例2 ③ until 循环语句结构 示例1 一 ...
- Shell编程之循环语句与echo的用法
Shell编程之循环语句与echo的用法 目录 Shell编程之循环语句与echo的用法 一.echo用法 1. echo常用选项 2. 常用的转义字符 3. 特殊符号%.#的用法 二.循环语句 1. ...
- Linux - 简明Shell编程06 - 循环语句(Loop)
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash # for循环 for fil ...
- shell编程之循环
一.for循环 for循环是Shelll中最常见的循环结构,根据书写习惯又分为列表for循环.不带列表的for循环以及类C的for循环.for循环是一种运行前的测试语句,也就是在运行任何循环体之前先要 ...
- Shell 编程(循环)
for in 循环语句 #!/bin/bash for x in one two three four do echo number $x done 例:取出passwd中每一行name 并输出 he ...
- Linux centosVMware shell编程 for循环、while循环、break跳出循环、continue结束本次循环、exit退出整个脚本
一.for循环 语法:for 变量名 in 条件; do …; done 案例1 #!/bin/bash sum=0 for i in `seq 1 100` do sum=$[$sum+$i] ec ...
- shell编程之循环语句
for #! /bin/sh for FRUIT in apple banana pear; do echo "I like $FRUIT" done while #! /bin/ ...
- shell编程基础(5)---循环指令
while类型的循环 while类型的循环是不定循环的一种,每一次循环都会验证给出的循环条件,判断是否要进行下一次循环.linux中while循环的写法和c语言中很想,但是条件给出的方式有些区别. 首 ...
- shell编程下 特殊变量、test / [ ]判断、循环、脚本排错
第1章 shell中的特殊变量 1.1 $# $# 表示参数的个数 1.1.1 [示例]脚本内容 [root@znix ~]# cat /server/scripts/show2.sh #!/bin/ ...
随机推荐
- Pinpoint - 应用性能管理(APM)平台实践之部署篇
0.0 前言 国内的APM行业这两年刚刚起步,但是在国外却比较成熟了,并且由于这两年人力成本的快速提高,国内外涌现了几家非常不错的APM企业,例如APPdynamic,Dynamic,NewRelic ...
- Android spinner 样式及其使用详解
设计与开发首页 > 应用专题 > 移动开发 > 正文> Android spinner 样式及其使用详解 相关文章: Android 开源项目应用程序与框架推荐 Android ...
- 自定义nsoperation的用法
#import <Foundation/Foundation.h> typedef void (^DownloadCompletionBlock)(UIImage *image); @in ...
- 【RS】CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Collaborative Filtering-CoupledCF:在推荐系统深度协作过滤中学习显式和隐式的用户物品耦合
[论文标题]CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Colla ...
- 最新的 CocoaPods 的使用教程(一)
发布开源库到CocoaPods的时候.对CocoaPods重新学习了一下. 1.CocoaPods的日常使用 2.创建CocoaPods的私有库 3.创建CocoaPods的开源库 一. CocoaP ...
- 【LeetCode】221. Maximal Square
Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...
- hibernate 注释 唯一键约束 uniqueConstraints
@Table 注解包含一个schema和一个catelog 属性,使用@UniqueConstraints 可以定义表的唯一约束. 如果是联合约束就用下面这种 @Table(name="tb ...
- Android面试之HashMap的实现原理
1.HashMap与HashTable的区别 HashMap允许key和value为null: HashMap是非同步的,线程不安全,也可以通过Collections.synchronizedMap( ...
- iOS Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to
刚接触iOS,依照教程操作执行出现错误 Terminating app due to uncaught exception 'NSInternalInconsistencyException', re ...
- the most beautiful media player on the linux platform.
the most beautiful media player on the linux platform------> deepin media player http://wiki.linu ...