diff --git a/02-Shell 流程控制_函数编程.md b/Shell 流程控制_函数编程.md similarity index 87% rename from 02-Shell 流程控制_函数编程.md rename to Shell 流程控制_函数编程.md index bd52364..4a392c2 100644 --- a/02-Shell 流程控制_函数编程.md +++ b/Shell 流程控制_函数编程.md @@ -1,6 +1,5 @@ - -# 02-Shell流程控制-函数 +# Shell流程控制-函数 ## 一、Shell 编程之条件结构 @@ -969,264 +968,3 @@ The factorial of 5 is: 120 **内建命令** ​ 因为安装了shell而产生的命令 - - - -# 作业01 - -要求最小化安装干净的系统,用脚本实现如下操作 - -```bash -先判断yum源是否可用 - -判断有没有epel yum源,如果没有则安装epel yum源 - -判断epel yum源是否可用,如果可用则安装sl - -判断sl是否可用,打印提示字符串 软件已经安装成功 - -安装httpd,安装完成后启动服务,判断服务是否可用 - - - - - - - - -#vim /bin/bash -#判断yum是否可用 -rpm -e lftp --nodeps -yum install lftp -y -rpm -q lftp -retval=$? - -if [ $retval -ne 0 ];then - echo yum有问题 && exit 2 -else - echo yum可用,请继续 -fi - - -#判断epel是否可用,安装sl工具 -yum install sl -y -retval=$? -if [ $retval -eq 0 ];then - echo EPEL源可用,且sl工具已安装 -else - echo EPEL不可用,将要安装epel,请稍后... - yum install epel-release -y - yum install sl -y -fi -sl -#安装并测试httpd服务 -yum install -y httpd -systemctl start httpd -curl localhost -[ $? -eq 0 ] && echo 'Httpd服务已安装且可用,恭喜你!!!' -``` - -``` -1.在上面脚本基础上添加脚本参数功能,用户可输入-v参数,参数的功能为显示详细测试过程 -``` - -``` -2.请试着写出一个杀死进程httpd的shell脚本 -``` - -``` -3.请利用shell开发一个rsync服务的启动停止脚本 -请利用shell开发一个rsync服务的管理脚本 - -a.sh - -``` - - - -服务的启动管理脚本 - -服务:编译安装的nginx 二进制安装的tomcat 编译安装的redis 编译安装的rsync - - - -过时技术 centos7之前使用的initd管理服务 - -centos7之后,包括7,官方用systemd替换initd - -systemd 的服务管理方式 - -``` -nginx 开机启动 - systemctl enable nginx - -nginx 启动 - systemctl start nginx -``` - -initd的服务管理方式 - -``` -nginx 开机启动 - chkconfig --level 5 nginx on - -nginx 启动 - service nginx start - /etc/init.d/nginx start - -自己编写的启动脚本默认不在chkconfig的管理之下 - chkconfig --add nginx - - - -``` - - - - - - - - - -# 常见环境变量 - -```bash -PATH变量 -存储命令路径 -# echo $PATH -/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/root/bin - -PS1 -存储提示符格式 -PS2 -存储2级提示符格式 - -SHELLS //本系统支持的shell - -PWD //当前工作目录 - -HOME //当前账户家目录 - -USER //当前登录账户 - -ID //当前账户ID - -LANG=zh_CN.UTF-8 //字符集 - -HISTSIZE //历史命令条数 - -HOSTNAME //当前主机名称 - -``` - - - -# 作业02 - -用shell打印如下图形 - -```bash -******** - -******** -******** -******** -******** - -* -** -*** -**** -***** -****** - - * - *** - ***** -******* - -要求以上图形在用户执行脚本时可以让用户指定行数和列数 - - * - *** - ***** -******* - *** - ***** -******* - *** - *** - *** -====生死分割线====== - * - * * - * * -******* - - -用shell编写编译安装的nginx启动管理脚本 - - - -``` - - - -# seq命令 - -打印连续的数字 - -```bash -# seq 10 -# seq 2 10 -# seq 2 3 10 -# seq 10 -1 2 -# seq 10 -3 2 -``` - -# 作业03 - -1. 编写shell脚本,为不同分数的同学评级 - -60分以下 不及格 - -60-70 合格 - -70-90 良好 - -其他 优秀 - -2. 使用case语句编写脚本service.sh ,当给脚本传入不同参数的时候,执行不同的操作 - -service.sh start - -服务启动成功 - -service.sh stop - -服务关闭成功 - -service.sh restart - -服务重启 - -service.sh restt - -语法错误 - -3.昨天ftp的作业,添加功能,判断文件是否下载成功,并给出提示 - - - - - - - - - - - - - - -