实例:选择安装

[root@iZcyriae88knxxZ cloudduo]# cat 20191203.sh 
#!/bin/bash
#first shell
#xia cheng feng
echo -e '\033[32m-----------------------------\033[0m'
echo "1)安装apache"
echo "2)安装nginx"
echo "3)安装php"
echo -e '\033[32m-----------------------------\033[0m'

实例:比数字大小

[root@iZcyriae88knxxZ cloudduo]# cat if.sh 
#!/bin/bash
# if
# xia chengfeng
if((1>2)); then
echo "1大于2"
else
echo "1小于2"
fi

实例:检查是否有对应目录,没有的话创建

[root@iZcyriae88knxxZ cloudduo]# cat mulu.sh
#!/bin/bash
#by xia chengfeng
if [ ! -d /root/wnana ];then
	mkdir -p /root/wnana
else 
	echo "/root/wnana 目录已存在不需要创建"
fi

实例:输出当前时间

[root@iZcyriae88knxxZ cloudduo]# cat echo.sh

#!/bin/bash 
# 输出日期
echo $(date +%Y%m%d)  >> /root/cloudduo/20191204.log
[root@iZcyriae88knxxZ cloudduo]# 
[root@iZcyriae88knxxZ cloudduo]# cat 20191204.log
[root@iZcyriae88knxxZ cloudduo]# ./echo.sh
[root@iZcyriae88knxxZ cloudduo]# cat 20191204.log
20191204