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. iOS多播Delegate类——GCDMulticastDelegate用法小结

    iOS中通常的delegate模式只能有一个被委托的对象,这样当需要有多个被委托的对象时,实现起来就略为麻烦,在开源库XMPPFramework中提供了一个GCDMulticastDelegate类, ...

  2. Xcode Warning: “no rule to process file

    警告⚠️: warning: no rule to process file '/Users/Kingdev/Desktop/Git/finance_iOS/finance/Library/MBpro ...

  3. mysql基础,事物

  4. python虚拟环境 virtualenv工具

    为了隔离各类环境,保证环境间不冲突,python中存在虚拟环境,可以在一个文件夹里生成相应的环境,防止与python自带环境冲突 首先我们下载virtualenv,若你未安装python,应到pyth ...

  5. git bash学习3 -简单杂乱知识点记录

    branch 新建分支 git init git add git commit 先新建一个仓库以及master 然后新建分支 git branch BranchName 然后切换分支 git chec ...

  6. nginx Keepalived高可用集群

    一.Keepalived高可用 1.简介 Keepalived软件起初是专为LvS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能.因此, ...

  7. LeetCode#453 最小移动次数使数组元素相等

    给定一个长度为 n 的非空整数数组,找到让数组所有元素相等的最小移动次数.每次移动可以使 n - 1 个元素增加 1. 示例: 输入: [,,] 输出: 解释: 只需要3次移动(注意每次移动会增加两个 ...

  8. 27.28. VUE学习之--事件修饰符之stop&capture&self&once实例详解

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

  9. wireshark_1.6.2 使用笔记

    表示ip1是否有访问ip2,进行抓包

  10. Unity 与Mono和.Net的关系

    一.分析 首先,我们要知道Unity,Mono,.Net 三者的关系.需要简单说一下.Net. .Net拥有跨语言,跨平台性. 跨语言:就是只要是面向.Net平台的编程语言,用其中一种语言编写的类型就 ...