四,if语句
复制代码 代码示例:
#!/bin/bash
echo "Input a number #1 "
read num
echo "variable #1 = $num"
if [ $num -lt 60 ] //注意lt前面的-,很容易忘的
then
echo "you are not pass"
elif [ $num -lt 70 ] && [ $num -ge 60 ] //多个条件的判断
then
echo "pass"
elif [[ $num -lt 85 && $num -ge 70 ]] //如果放在一起,要注意是双方括号,不要写成[ $num -lt 85 && $num -ge 70 ]
then
echo "good"
elif (( $num <= 100 )) && (( $num >= 85 )) //对于有语言基础的人来说,这种写法让人觉得很舒服,不要忘了是双小括号
then
echo "very good"
else
echo "num is wrong"
fi //if要有结束标签的,根XML很像,不闭合,就报错
exit 0
五,case语句
复制代码 代码示例:
#!/bin/sh
case $1 in
start)
echo "start ok"
;; //注意一点,要注意是双分号
stop)
echo "stop ok"
;;
restart)
echo "restart ok"
;;
*)
echo "no param"
;;
esac //注意闭合标签
exit 0
[root@e
cms forif]# sh c1.sh stop
stop ok