grep-v$p1$file_name>tmp.txt
echo"$p1,$p2">>tmp.txt
IFS=""
mvtmp.txt$file_name
dialog--title"ReplyInfo"--msgbox"Theinformationhasbeenmodified!
"1030
}
status=1
dialog--title"Students'InfoManageSystem"--msgbox"\\nWelccometousetheSystem!
\\n"1035
if[$?
!
=0];then
sleep1
dialog--clear
exit0
fi
while["$status"="1"]
do
dialog--title"MainMenu"--menu"Choices"152021"Student"2"College"2>tmp.txt
MY_CHOICE=$(cattmp.txt)
if[$?
!
=0];then
sleep1
dialog--clear
exit0
fi
if["$MY_CHOICE"="1"];then
dialog--title"StudentInfoManage"--menu"ChooseOperation"203071"INSERT"2"DELETE"3"MODIFY"4"COUNT"5"DISPLAY"6"BACK"7"EXIT"2>tmp.txt
if[$?
!
=0];then
sleep1
dialog--clear
exit0
fi
choice_2=$(cattmp.txt)
if["$choice_2"="1"];then
insert_s
elif["$choice_2"="2"];then
delete_s
elif["$choice_2"="3"];then
change_s
elif["$choice_2"="4"];then
count
elif["$choice_2"="5"];then
display_s
elif["$choice_2"="6"];then
continue
else
break
fi
else
dialog--title"CollegeInfoManage"--menu"ChooseOperation"203071"INSERT"2"DELETE"3"MODIFY"4"COUNT"5"DISPLAY"6"BACK"7"EXIT"2>tmp.txt
if[$?
!
=0];then
sleep1
dialog--clear
exit0
fi
choice_2=$(cattmp.txt)
if["$choice_2"="1"];then
insert_c
elif["$choice_2"="2"];then
delete_c
elif["$choice_2"="3"];then
change_c
elif["$choice_2"="4"];then
count
elif["$choice_2"="5"];then
display_c
elif["$choice_2"="6"];then
continue
else
break
fi
fi
dialog--yesno"Doyouwanttocontinue?
"1020
if[$?
=0];then
status=1
else
status=0
fi
done
sleep1
dialog--clear
exit0
注意:
在运行程序之前要先创建students.db和colleges.db这两个文件,不然会出错
运行结果:
(1)欢迎界面和主界面
(2)"选择操作"界面
(3)插入一条记录
(4)显示所有的学生/学院信息
(5)删除一条记录
(6)修改记录
(7)经过删除修改后的信息
(8)统计某个学院的学生数
学生成绩管理
viewplaincopytoclipboardprint?
1.##Power by oAthEvil
2.##E-mail:
oathevil@
3.##Blog:
4.#!
/bin/bash
5.
6.DIALOG=/usr/bin/dialog
7.TMP="./tmp/tmp.$"
8.FILE_FACULTY="./file/Faculty.dat"
9.FILE_STUDENT="./file/Student.dat"
10.FILE_SCORE="./file/Score.dat"
11.msg() {
12. $DIALOG --title "Prompt" --msgbox "$1" 15 30
13.}
14.
15.Insert() {
16. case "$1" in
17. Faculty)
18. #### Get faculty id to be inserted
19. $DIALOG --title "$1" --inputbox "Enter [Faculty Id]:
" 6 30/
20. 2> ${TMP}_INSERT_INS
21. faculty_id=$(cat ${TMP}_INSERT_INS)
22. #### Check If the record of $faculty exists
23. export n=$(cat $FILE_FACULTY | grep "^${faculty_id}," | wc -l | tr -d " ")
24. if [ "x$n" !
= "x0" ] || [ "x$faculty_id" = "x" ] ; then
25. msg "Invalid faculty id or already exsitance !
"
26. return
27. fi
28. #### Get faculty name to be inserted
29. $DIALOG --title "$1" --inputbox "Enter [Faculty Name]:
" 6 30/
30. 2> ${TMP}_INSERT_INS
31. faculty_name=$(cat ${TMP}_INSERT_INS)
32. #### Check if faculty id and faculty name to be inserted are valid
33. if [ "x$faculty_id" = "x" ] || [ "x$faculty_name" = "x" ] ; then
34. if [ "x$faculty_id" = "x" ] ; then
35. msg "Invalid faculty id !
"
36. else
37. msg "Invalid faculty name !
"
38. fi
39. else
40. echo $faculty_id,$faculty_name >> $FILE_FACULTY
41. msg "Insert record successfully !
"
42. fi
43.
44. rm -f ${TMP}_INSERT_INS
45. ;;
46. Student)
47. #### Get Student id to be inserted
48. $DIALOG --title "$1" --inputbox "Enter [Student Id]:
" 6 30/
49. 2> ${TMP}_STUDENT_INS
50. student_id=$(cat ${TMP}_STUDENT_INS)
51.
52. #### Check If the record of $student_id exists
53. export n=$(cat $FILE_STUDENT | grep "^${student_id}," | wc -l | tr -d " ")
54. if [ "x$n" !
= "x0" ] || [ "x$student_id" = "x" ] ; then
55. msg "Invalid student id or already exsitance !
"
56. return
57. fi
58.
59. $DIALOG --title "$1" --inputbox "Enter [Student Name]:
" 6 30/
60. 2> ${TMP}_STUDENT_INS
61. student_name=$(cat ${TMP}_STUDENT_INS)
62. if [ "x$student_name" = "x" ] ; then
63. msg "Invalid student name !
"
64. return
65. fi
66.
67. $DIALOG --title "$1" --inputbox "Enter [Faculty Id]:
" 6 30/
68. 2> ${TMP}_STUDENT_INS
69. faculty_id=$(cat ${TMP}_STUDENT_INS)
70.
71. if [ "x$faculty_id" = "x" ] ; then
72. msg "Invalid faculty id !
"
73. return
74. fi
75.
76. $DIALOG --title "$1" --inputbox "Enter [Student Status]:
" 6 30/
77. 2> ${TMP}_STUDENT_INS
78. student_status=$(cat ${TMP}_STUDENT_INS)
79.
80. if [ "x$student_status" = "x" ] ; then
81. msg "Invalid student status!
"
82. return
83. fi
84. echo $student_id,$student_name,$faculty_id,$student_status>> $FILE_STUDENT
85. msg "Insert record suc