(1)
if 条件; then
命令
fi
等价于:if 条件 ##不用;
then
命令
fi
(2)
if 条件; then
命令
else
命令
(3)
if 条件; then
命令
elif 条件;then
命令
elif 条件;then
命令
else
命令
fi
(4)
read -p "是否确认[y]:" kvm
if[! $kvm ="y"];then
echo -e "不正确"
fi
eg1:
删除网关:
ip r
ip r del default via 192.168.122.1#!/usr/bin/bash#install apache#v1.0 by wangji 2020-2-19
ping -c1 www.baidu.com &>/dev/null
if[ $? -ne 0];then
echo "connect: unreachable"
exit
fi
yum -y install httpd
systemctl start httpd
systemctl enable hrrpd
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##以SELINUX开头的行,/c表示换成SELINUX=disabled