-
Notifications
You must be signed in to change notification settings - Fork 3
/
Mini-Library-Management-System.sh
175 lines (142 loc) · 2.77 KB
/
Mini-Library-Management-System.sh
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
menu_choice=""
record_file="bookRecords.ldb"
temp_file=/tmp/ldb.$$
touch $temp_file; chmod 644 $temp_file
trap 'rm -f $temp_file' EXIT
get_return(){
printf '\tPress return\n'
read x
return 0
}
get_confirm(){
printf '\tAre you sure?\n'
while true
do
read x
case "$x" in
y|yes|Y|Yes|YES)
return 0;;
n|no|N|No|NO)
printf '\ncancelled\n'
return 1;;
*) printf 'Please enter yes or no';;
esac
done
}
set_menu_choice(){
clear
printf 'Options:-'
printf '\n'
printf '\ta) Add new Books records\n'
printf '\tb) Find Books\n'
printf '\tc) Edit Books\n'
printf '\td) Remove Books\n'
printf '\te) View Books\n'
printf '\tf) Quit\n'
printf 'Please enter the choice then press return\n'
read menu_choice
return
}
insert_record(){
echo $* >>$record_file
return
}
add_books(){
printf 'Enter Books category:-'
read tmp
liCatNum=${tmp%%,*}
printf 'Enter Books title:-'
read tmp
liTitleNum=${tmp%%,*}
printf 'Enter Auther Name:-'
read tmp
liAutherNum=${tmp%%,*}
printf 'About to add new entry\n'
printf "$liCatNum\t$liTitleNum\t$liAutherNum\n"
if get_confirm; then
insert_record $liCatNum,$liTitleNum,$liAutherNum
fi
return
}
find_books(){
echo "Enter book title to find:"
read book2find
grep $book2find $record_file > $temp_file
linesfound=`cat $temp_file|wc -l`
case `echo $linesfound` in
0) echo "Sorry, nothing found"
get_return
return 0
;;
*) echo "Found the following"
cat $temp_file
get_return
return 0
esac
return
}
remove_books() {
linesfound=`cat $record_file|wc -l`
case `echo $linesfound` in
0) echo "Sorry, nothing found\n"
get_return
return 0
;;
*) echo "Found the following\n"
cat $record_file ;;
esac
printf "Type the books titel which you want to delete\n"
read searchstr
if [ "$searchstr" = "" ]; then
return 0
fi
grep -v "$searchstr" $record_file > $temp_file
mv $temp_file $record_file
printf "Book has been removed\n"
get_return
return
}
view_books(){
printf "List of books are\n"
cat $record_file
get_return
return
}
edit_books(){
printf "list of books are\n"
cat $record_file
printf "Type the tile of book you want to edit\n"
read searchstr
if [ "$searchstr" = "" ]; then
return 0
fi
grep -v "$searchstr" $record_file > $temp_file
mv $temp_file $record_file
printf "Enter the new record"
add_books
}
rm -f $temp_file
if [!-f $record_file];then
touch $record_file
fi
clear
printf '\n\n\n'
printf 'Mini library Management'
sleep 2
quit="n"
while [ "$quit" != "y" ];
do
set_menu_choice
case "$menu_choice" in
a) add_books;;
b) find_books;;
c) edit_books;;
d) remove_books;;
e) view_books;;
f) quit=y;;
*) printf "Sorry, choice not recognized";;
esac
done
rm -f $temp_file
echo "Finished"
exit 0