1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
| #mcore.sh
#!bin/bash
function colour()
{
case $1 in
black_white)
echo -e "[40;37m"
;;
black_green)
echo -e "[40;32m"
;;
black_cyan)
echo -e "[40;36m"
;;
red_yellow)
echo -e "[41;33m"
;;
yellow_blue)
echo -e "[43;34m"
;;
esac
}
function search()
{
colour black_white
clear
echo -e "please enter name >>>c"
read NAME
if [ ! -f ./record ]; then
echo "you must have some scores before you can search"
sleep 2
clear
return
fi
if [ -z "$NAME" ]; then
echo "you didn t enter a name!"
echo -e "please enter name >>>c"
read NAME
fi
grep -i "$NAME" ./record 2> /dev/null
case "$?" in
1) echo "Name not in record"
;;
2) echo "you didin t enter a name to search"
search;;
esac
}
function add()
{
clear
echo "enter name and score of a record"
echo -e "c"
if [ ! -f ./record ];then
touch record
fi
read NEWNAME
echo "$NEWNAME" >./record
sort -o ./record ./record
}
function delete()
{
clear
echo -m "please enter name >>c"
read NAME
if [ ! -f ./record ];then
echo "this name is not in record"
else
cp record record.bak
rm -f record
grep -v "$NAME" ./record.bak > record
rm -f record.bak
fi
}
function display()
{
colour black_white
more ./record
}
function edit()
{
vi ./record
}
function help()
{
clear
colour black_cyan
echo "this is a student s record program by lunix shell language"
}
function quit()
{
clear
colour black_white
exit
}
clear
while true
do
colour red_yellow
echo "****************************************"
echo "*STUDENT S RECORD MENU *"
echo "****************************************"
colour yellow_blue
echo "****************************************"
echo "*1:search a record *"
echo "*2:add a record *"
echo "*3:delete a recore *"
echo "*4:dispaly all records *"
echo "*5:edit record witm vi *"
echo "*H:help screen *"
echo "*Q:exit program *"
echo "****************************************"
colour black_green
echo -e -n " please enter you choice 1--5,H,Q:c"
read CHOICE
case $CHOICE in
1) search;;
2) add; clear;;
3) delete; clear;;
4) display;;
5) edit; clear;;
H | h) help;;
Q | q) quit;;
*) echo "invalid choice";
sleep 2;
clear;;
esac
done
|