主要分为if和case两大部分。
if语句
#!/bin/bash
#test6
read -p "please input a number:" number
if [ $number -lt 20 ]
then
echo "小于20"
elif [ $number -lt 10 ]
then
echo "小于10"
else
echo "大于等于20"
fi
case语句
判断周几的shell
#!/bin/bash
#test7.sh
week=`date +%w `
case $week in
1)
echo '周一'
;;
2)
echo '周二'
;;
*)
echo '其他'
;;
esac
模拟启动脚本
#!/bin/bash
#test8.sh
case $1 in
start)
echo 'start...'
;;
stop)
echo 'stop...'
;;
restart)
echo 'restart'
;;
*)
echo 'please input start|stop|restart'
;;
esac