-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
138 lines (103 loc) · 2.85 KB
/
backup.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
#!/usr/bin/ksh
tst="north";
test=$tst":";
# echo $test;
number='"/^[0-9]+$/"'
mix='"/^[A-Za-z]+ [a-z0-9]*/"'
text='"/^[A-Za-z]+ [a-z]*/"'
menu='"/^soft_cover$\|^hard_cover$/"'
year='"/^[0-9][0-9][0-9][0-9]$/"'
# x=$(awk -F: -v env_var="$tst" '{if($2==env_var) print $2 }' libs/lib1/shelves);
# echo $x;
# sed -i '/^'"$test"'/d' libs/lib1/shelves
# echo $a;
# echo ${a[@]}
#
# # # sed 's/$t'"$t"'//'.
# for x in ${a[@]}
# do
# echo $x
# done
# for (( i = 0; i <${#a[*]}; i+=2 )); do
# echo "thea =" ${a[$i]};
# x= $"a[$i+1]";
# # echo '$x '
# done
adddddbook(){
a=($(awk -F:: '{print $1 ,$2}' libs/lib1/meta))
typeset -i i;
typeset -i j;
for ((j=0, i = 0; i < ${#a[*]}; i+=2,j++ )); do
tmp="";
while [[ $tmp = "" ]]; do
# regex= ${!a[$i+1]};
if [[ ${a[$i]} == "Cover_type" ]]; then
echo "Enter 1 for soft_cover or 2 for hard_cover : "
select tmp in soft_cover hard_cover
do
case $tmp in
soft_cover)
echo "Soft cover"
tmp=$tmp" ::";
book[j]=${tmp}
break
;;
hard_cover)
echo "Hard cover"
tmp=$tmp" ::";
book[j]=${tmp}
break
;;
*) echo "ERROR: Invalid selection enter 1 or 2 only "
;;
esac
done
else
echo "Please Enter ${a[$i]} :-"
read tmp
# ${${a[$i+1]}//""}
regex=${a[$i+1]}
regex="${regex%\"}"
regex="${regex#\"}"
# echo "$regex "
if [[ $tmp =~ $regex ]]; then
chk="";
if [[ ${a[$i]} == "Title" ]]; then
chk=$(awk -F:: -v env_var="$tmp" '{if($2==env_var) print $2}' libs/lib1/books);
# t=$(awk -F: -v a=$tmp '{if($1==$a) print $1}' shelves)
# echo "$t"
# echo "$chk"
if [[ $chk ]]; then
echo "book Title exist try another one "
tmp="";
else
tmp=$tmp" ::";
book[j]=${tmp};
fi
else
tmp=$tmp" ::";
book[j]=${tmp};
fi
if [[ ${a[$i]} == "ISBN" ]]; then
chk=$(awk -F:: -v env_var="$tmp" '{if($1==env_var) print $1}' libs/lib1/books);
# t=$(awk -F: -v a=$tmp '{if($1==$a) print $1}' shelves)
# echo "$t"
# echo "$chk"
if [[ $chk ]]; then
echo "book ISBN exist try another one "
tmp="";
else
tmp=$tmp" ::";
book[j]=${tmp};
fi
fi
else
echo "Non vallid entery ";
tmp="";
fi
fi
done
done
echo ${book[@]} >>"libs/lib1/books"
}
adddddbook