Linux基础-shell-if-elif-else-fi

例子: 安装apache脚本

#!/bin/bash

#install apache

#v1.0 by zhengjx

ping -c2 www.baidu.com &>/dev/null

if [ $? -eq 0 ];then

        read -p "确定安装Apache[y]: " action_install_apache

        if [ "$action_install_apache" = "y" ];then


                yum install -y httpd

                systemctl start httpd

                systemctl enable httpd

                firewall-cmd --permanent --add-service=http

                firewall-cmd --permanent --add-service=https

                firewall-cmd --reload

                sed -ri '/^SELINUX=/cSELINUX=disabled/' /etc/selinux/config

                setenforce 0

                curl http://127.0.0.1 &>/dev/null

                if [ $? -eq 0 ];then

                        echo "Apache 安装成功!"

                fi

        else   

                echo "输入错误,确认输入y"

                exit

        fi

elif

        ping -c2 127.0.0.1;then

        echo "check network cards!" 

elif   

        grep "nameserver" /etc/reslov.conf; then

        echo "please check DNS"

fi

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容