- 打印99乘法表:
- #!/bin/bash
- fornumin`seq9`
- do
- fornum1in`seq9`
- do
- if[$num-ge$num1];then
- if((($num*$num1))>9)
- then
- echo-ne"${num}x${num1}=$(($num*$num1))\t"
- else
- echo-ne"${num}x${num2}=$(($num*$num1))\t"
- fi
- fi
- done
- echo-ne"\n"
- done
for循环语句的企业高级实战案例:
不登陆MysqL创建数据库的命令为MysqL -uroot -p*** -S 、data/MysqL.sock -e "create database dbname";
模拟生产环境,创建库然后进行分库备份。
- #!/bin/bash
- exportLANG="zh_CN.UTF-8"
- PATH=/usr/local/MysqL/bin:$PATH
- #user=root
- #passwd=123456
- backup=/tmp/backup
- sock=/var/lib/MysqL/MysqL.sock
- #comm="MysqL-uroot-e"createdatabase$dbname""
- [!-d$backup]&&mkdir$backup
- fordbnameinabc
- do
- echo"创建dbname$dbname"
- MysqL-uroot-S$sock-e"createdatabase$dbname"
- echo"开始备份$dbname"
- MysqLdump-uroot-S$sock$dbname|gzip>>$backup/"$dbname"_$(date+%F).sql.gz
- done