CC 4.0 BY-SA 版权协议网址:https://creativecommons.org/licenses/by-sa/4.0/deed.z
站主补充:
补充一:Shell if 单判断的格式
if [ <判断条件> ]; then
<要执行的步骤>
fi
补充二:Shell if 双判断的格式
if [ <判断条件> ]; then
<要执行的步骤>
else
<要执行的步骤>
fi
补充三:Shell if 多判断的格式
if [ <判断条件> ]; then
<要执行的步骤>
elif
<要执行的步骤>
else
<要执行的步骤>
fi
补充四:Shell if 多条件判断的格式
4.1 与条件的判断
if [ <判断条件> -a <判断条件> ]; then
<要执行的步骤>
fi
4.2 或条件的判断
if [ <判断条件> -o <判断条件> ]; then
<要执行的步骤>
fi
#!/bin/bash
#At the system level, start the database as a MySQL user
chown -R mysql /var/lib/mysql
sed -i '/^user=/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i '/^datadir/a user=mysql' /etc/my.cnf.d/mariadb-server.cnf
#Disable client local data reading at the system level
sed -i '/^local-infile=/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i '/^datadir/a local-infile=0' /etc/my.cnf.d/mariadb-server.cnf
#At the system level, remote login of database is prohibited
sed -i '/^bind-address=/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i '/^datadir/a bind-address=127.0.0.1' /etc/my.cnf.d/mariadb-server.cnf
#Restart database
systemctl restart mariadb ; systemctl restart mysql
case <variable> in
<variable value 1>)
<the command to execute when the variable is this value>;;
<variable value 2>)
<the command to execute when the variable is this value>;;
<variable value 3>)
<the command to execute when the variable is this value>;;
*)
<the command to execute when the variable value is other>;;
esca
内容二:case 语句的使用案例
#!/bin/bash
read -p "Which one do you like better, eternalcenter eternalcentre ec-x : " name
case $name in
eternalcenter)
echo "Do you realy like $name better? eternalcenter?" ;;
eternalcentre)
echo "Do you realy like $name better? eternalcentre?" ;;
ec-x)
echo "Do you realy like $name better? ec-x?" ;;
*)
echo "So you don't like them all ." ;;
esac