Linux基础之简易Shell 程序设计

编写一段 bash Shell 程序,根据从键盘输入的学生成绩,显示相应的成绩等级,其中60 分以下为“Failed!”,60~70 分为“Passed!”,70~80 分为“Medium!”,80~90 分为“Good!”,90~100 分为“Excellent!”。如果输入超过 100 或负数的分数,则显示错误分数提示

实现代码:

#!/bin/bash

#input the score then display the grade level

echo "Input the student's score ,please"

read score

if [ "${score}" -gt 100 ];

then

echo "Wrong score"

elif [ "${score}" -ge 90 ]; then

echo "Excellent"

elif [ "${score}" -ge 80 ]; then

echo "Good"

elif [ "${score}" -ge 70 ]; then

echo "Medium"

elif [ "${score}" -ge 60 ]; then

echo "Passed"

elif [ "${score}" -lt 60 ]; then

echo "Wrong score"

else

echo "please again"

fi

exit 0


你可能感兴趣的:(Linux基础)