计算成绩练习脚本

作者: admin 分类: Mysql,Shell脚本 发布时间: 2021-12-17 17:46 浏览:397 次    
#!/bin/sh

red()
{
read -p "请输入姓名:" name
read -p "语文成绩:" yuwen
read -p "数学成绩:" shuxue
read -p "英语成绩:" waiyu

if [ -z "`echo $yuwen|sed 's/[1-9]//g'`" -a -z "`echo $shuxue|sed 's/[0-9]//g'`" -a -z "`echo $waiyu|sed 's/[0-9]//g'`" ];then
   sum=$((yuwen+shuxue+waiyu))
   ave=$((sum/3))
   echo "${name}的成绩:${sum}  平均分:${ave}"
else
   echo "成绩输入错误,请检查后重新输入"
fi
}

main()
{
red
while :
do
   read -p "是否继续输入(y-继续,n-退出): " xuanze
   if [ $xuanze == y ];then
      red
   elif [ $xuanze == n ];then
      exit
   else
      echo "选择输入错误,请重新选择"
   fi
done
}

main

温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!

发表评论