-
Notifications
You must be signed in to change notification settings - Fork 0
/
shelv.sh
executable file
·131 lines (106 loc) · 2.61 KB
/
shelv.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
#!/usr/bin/ksh
insert_shelve_record(){
echo $* >>"shelves"
return
}
# check_shelve
addShelve(){
echo "addShelve"
#prompt for information
tmp="";
while [[ $tmp = "" ]]; do
printf 'Please Enter shelve location:- '
read tmp
if [[ $tmp == +([A-za-z]) ]]; then
chk="";
chk=$(awk -F: -v env_var="$tmp" '{if($1==env_var) print $1}' shelves);
# t=$(awk -F: -v a=$tmp '{if($1==$a) print $1}' shelves)
# echo "$t"
# echo "$chk"
if [[ $chk ]]; then
echo "shelve location exist try another one "
tmp="";
else
shelveLoc=${tmp};
fi
else
echo "shelve location cann't contain space or numbers ";
tmp="";
fi
done
tmp="";
while [[ $tmp = "" ]]; do
printf 'Please Enter shelve number:- '
read tmp
if [[ $tmp == +([0-9]) ]]; then
chk="";
chk=$(awk -F: -v env_var="$tmp" '{if($2==env_var) print $2}' shelves);
if [[ $chk ]]; then
echo "shelve number exist try another one "
tmp="";
else
shelveNum=${tmp};
fi
else
print "shelve number cann't contain space or characters ";
tmp="";
fi
done
#Check that they want to enter the information
printf 'About to add new entry\n'
printf "$liCatNum\t$liTitleNum\t$liAutherNum\n"
#If confirmed then append it to the record file
if get_confirm; then
insert_shelve_record $shelveLoc:$shelveNum
fi
return
}
deleteShelve(){
echo "deleteShelve"
a=($(awk -F: '{print $1}' shelves))
# echo $a;
a[${#a[*]}]="Quit"
echo "chose shelve to delete by entering it's number or quit by choseing Quit "
select alias_select in ${a[@]} ; do
if [[ -z "$alias_select" ]]; then
echo "Invalid Choice"
elif [[ $alias_select == "Quit" ]]; then
break
else
echo "You selected: $alias_select";
alias_select=$alias_select":";
sed -i '/^'"$alias_select"'/d' shelves
#func
fi
done
}
shelve_choice(){
echo " Enter 1 to add shelve or 2 to delete shelve or 3 to quit"
printf 'Options:-'
printf '\n'
printf '\t1) add shelve\n'
printf '\t2) delete shelve \n'
printf '\t3) Quit\n'
read shelve_ch
return
}
shelvebooks(){
echo "chose shelves or books or quit by choseing Quit "
echo " 1) shelves"
echo " 2) books"
echo " 3) quits"
}
shelve_selected(){
quit="n"
while [ "$quit" != "y" ];
do
shelve_choice
case "$shelve_ch" in
1) addShelve ;;
2) deleteShelve;;
3) shelvebooks
quit=y ;;
*) printf "Sorry, choice not recognized";;
esac
done
}