for循环语法结构如下

[root@backup tmp]# cat .sh
#!/bin/bash
for i in `seq `
do
echo $i
done
[root@backup tmp]# sh .sh 3 批量修改文件名

[root@backup tmp]# ll *.txt
-rw-r--r-- 1 root root 0 May 11 21:34 1.txt
-rw-r--r-- 1 root root 0 May 11 21:34 2.txt
-rw-r--r-- 1 root root 0 May 11 21:34 3.txt
-rw-r--r-- 1 root root 0 May 11 21:34 4.txt
-rw-r--r-- 1 root root 0 May 11 21:34 5.txt
[root@backup tmp]#
[root@backup tmp]# cat 2.sh
#!/bin/bash
cd /tmp
for filename in `ls|grep "txt$"`
do
mv $filename `echo $filename |cut -d . -f1`.gif


done
[root@backup tmp]# sh 2.sh
[root@backup tmp]# ll
total 8
-rw-r--r-- 1 root root 0 May 11 21:34 1.gif
-rw-r--r-- 1 root root 49 May 11 21:33 1.sh
-rw-r--r-- 1 root root 0 May 11 21:34 2.gif
-rw-r--r-- 1 root root 115 May 11 21:39 2.sh
-rw-r--r-- 1 root root 0 May 11 21:34 3.gif
-rw-r--r-- 1 root root 0 May 11 21:34 4.gif
-rw-r--r-- 1 root root 0 May 11 21:34 5.gif

create table t1 (id int(4),name varchar(10));

insert into t1(id,name) values (1,'martin');

分库备份mysql数据库

[root@lnmp01 ~]# cat 1.sh
#!/bin/bash
PATH="application/mysql/bin:$PATH"
DBPATH=/server/backup
MYSQLROOT=root
MYPASS=hello123
SOCKET=/tmp/mysql.sock
MYCMD="mysql -u$MYSQLROOT -p$MYPASS -S $SOCKET"
MYDUMP="mysqldump -u$MYSQLROOT -p$MYPASS -S $SOCKET"

[ ! -d $DBPATH ]&& mkdir -p $DBPATH

for dbname in `$MYCMD -e "show databases;"|sed '1,2d'|egrep -v "mysql|schema"` #获取数据库名
do
$MYDUMP $dbname |gzip >$DBPATH/${dbname}_$(date +%F).sql.gz
done
[root@lnmp01 ~]#
[root@lnmp01 ~]# sh 1.sh
[root@lnmp01 ~]# ll /server/backup/
total 12
-rw-r--r-- 1 root root 680 Sep 20 12:16 discusz_2017-09-20.sql.gz
-rw-r--r-- 1 root root 7693 Sep 20 12:16 wordpress_2017-09-20.sql.gz

shell for 循环实践的更多相关文章

  1. Linux 之Shell for循环

    @代表所有参数所以如果后面跟上echo $v你会发现他会一次显示user userdebug eng $poo -le ${#prodlist[@]} 这句话是说 $poo小于等于prodlist中的 ...

  2. Shell脚本最佳实践

    Shell脚本最佳实践 0. 编码.缩进.文件命名和权限设置等 使用utf-8编码: 统一使用tab缩进或空格缩进,不要混用: 文件名以.sh结尾,并且统一风格: 添加可执行权限: chmod +x ...

  3. Linux Shell系列教程之(十二)Shell until循环

    本文是Linux Shell系列教程的第(十二)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上两篇文章Linux Shell系列教程之(十)Shell for循环和Lin ...

  4. shell for循环+case的脚本(监控程序状态)

    分享一个shell for循环+case的脚本(监控程序状态) 分享一个for循环+case的脚本(监控程序状态并执行相关操作) ,供大家学习参考. 复制代码代码如下: #/bin/bash set ...

  5. shell 各种循环判断

    shell支持的循环有 Shell if else Shell case esac Shell for循环 Shell while循环 Shell until循环

  6. shell脚本--循环结构

    shell的循环结构有while和for两种 for循环 #!/bin/bash #文件名:test.sh i=4 for i in 2 4 6 8 10 do echo $i done echo $ ...

  7. Linux Shell系列教程之(十一)Shell while循环

    本文是Linux Shell系列教程的第(十一)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上一篇Linux Shell系列教程之(十)Shell for循环中,我们已经 ...

  8. Linux Shell系列教程之(十)Shell for循环

    本文是Linux Shell系列教程的第(十)篇,更多Linux Shell教程请看:Linux Shell系列教程 基本任何语言都有自己的循环语句,Shell当然也不例外,今天就为大家介绍下Shel ...

  9. shell脚本-循环选择语句

    shell脚本-循环选择语句 过程式编程语言: 顺序执行 选择执行 循环执行 注:条件中的变量,可以在执行语句中使用,不用在加上"$". if语句 根据命令的退出状态来执行命令 单 ...

随机推荐

  1. 基于纹理内存的CUDA热传导模拟

    原文链接 项目中有三个,第一个是全局内存,其余两个分别是基于1d和2d纹理内存.项目打包下载. 纹理内存是只读内存,与常量内存相同的是,纹理内存也缓存在芯片中,因此某些情况下,它能减少对内存的请求并提 ...

  2. Linux网络编程之"获取网络天气信息"

    需求分析: 1.需要Linux c 网络编程基础, 2.需要了解 http 协议 3.需要天气信息相关api(可以从阿里云上购买,很便宜的!) 4.需要cJSON解析库(因为获取到的天气信息一般是用c ...

  3. 21.VUE学习之-操作data里的数组变异方法push&unshit&pop&shift的实例应用讲解

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. B1056 组合数的和 (15分)

    B1056 组合数的和 (15分) 给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字.要求所有可能组合出来的 2 位数字的和.例如给定2.5.8,则可以组合出: ...

  5. Codeforces Round #464 (Div. 2) A Determined Cleanup

    A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...

  6. 最短路径:HDU2006-一个人的旅行(多个起点,多个终点)

    题目: 一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. P3386 【模板】二分图匹配(匈牙利&最大流)

    P3386 [模板]二分图匹配 题目背景 二分图 题目描述 给定一个二分图,结点个数分别为n,m,边数为e,求二分图最大匹配数 输入输出格式 输入格式: 第一行,n,m,e 第二至e+1行,每行两个正 ...

  8. Redis实现之压缩列表

    压缩列表 压缩列表(ziplist)是列表键和哈希键的底层实现之一,当一个列表键只包含少量列表项,并且每个列表项要嘛是整数值,要嘛是比较短的字符串,那么Redis就会使用压缩列表来做列表键的底层实现. ...

  9. java的类加载器体系结构和双亲委派机制

    类加载器将字节码文件加载到内存中,同时在方法区中生成对应的java.land.class对象  作为外部访问方法区的入口. 类加载器的层次结构: 引导类加载器<-------------扩展类加 ...

  10. mysql查询当天的数据

    mysql查询当天的数据 贴代码: #两个时间都使用to_days()函数 select * from reple where to_days(create_time) = to_days(NOW() ...