linux学习笔记-学生信息管理系统(shell编程)

功能

1.向文件中插入记录
2.显示文件中的每条记录的每个字段值
3.从文件中修改指定学号的记录
4.对学生成绩进行统计(包括每个学生总成绩;每个学科前3名和总成绩前5名统计)

#!/bin/sh
insertMsg()
{
   echo "1,Student's basic Message"
   echo "2,Student's Marks Message"
   read yourSel
   if test "$yourSel" = "1" 
    then
        echo "input you want to add Student's basic Message"
        read stu_bas_msg
        echo "$stu_bas_msg" >>StudentMsg.txt
        echo "Save success"
   else
        echo "input you want to add Student's Marks Message"
        read stu_marks
        echo "$stu_marks" >>StudentMarks.txt
        echo "Save success"
   fi
}

outputSelStuMsg()
{
    echo "Enter student id you want to find a student"
    read student_id
    return_msg=$(ps -ef|grep -rn "$student_id" StudentMsg.txt)
    stu_finalmsg=${return_msg#*:}
    stu_finalmsg=${stu_finalmsg%,*}
    school_id=${return_msg##*,}
    school_name=$(ps -ef|grep -rn "$school_id" SchoolofMsg.txt)
    school_name=${school_name##*,}
    echo " Sno Sname major "
    echo "$stu_finalmsg,$school_name"
}


updataStudentMessage()
{
    echo "The input you want to modify the student's student id"
    read student_nub
    echo "input Sname,school_id and so on"
    sed  -i "/$student_nub/d" StudentMsg.txt
    read newMsg 
    echo "$newMsg" >>StudentMsg.txt    
    echo "updata success!"  
}

outputStudentMarksSum()
{
    sort -r ',' -k 4 StudentMarks.txt
}

echo "1, output student"
echo "2,update student"
echo "3, output sort"
echo "4,result"
echo "5,exit"
read i
case "$i" in
1)  insertMsg;;
2)  outputSelStuMsg;;
3)  outputSelStuMsg;;
4)  outputStudentMarksSum;;
5)  exit 0;;
esac
exit 0

运行结果

linux学习笔记-学生信息管理系统(shell编程)_第1张图片

linux学习笔记-学生信息管理系统(shell编程)_第2张图片


linux学习笔记-学生信息管理系统(shell编程)_第3张图片

你可能感兴趣的:(linux学习笔记-学生信息管理系统(shell编程))