if语法
多行写法语法
if 条件
then
命令
fi
可以将if语句放如一行语法
if 条件; then 命令; fi
if else 语法
if 条件
then
命令
else
命令
fi
if elif else语法
if 条件1
then
命令1
elif 条件2
then
命令2
elif 条件3
then
命令3
……
else
命令N
fi
演示
需求:
read -p "请输入你的考试成绩:" score
if [ $score -lt 0 ]
then
echo "成绩不合法"
elif [ $score -lt 60 ]
then
echo "不及格"
elif [ $score -ge 60 ] && [ $score -lt 70 ]
then
echo "及格"
elif [ $score -ge 70 ] && [ $score -lt 80 ]
then
echo "中等"
elif [ $score -ge 80 ] && [ $score -lt 90 ]
then
echo "良好"
elif [ $score -ge 90 ] && [ $score -le 100 ]
then
echo "优秀"
else
echo "成绩不合法"
fi