-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_zizo_edition.sh
97 lines (88 loc) · 2.47 KB
/
script_zizo_edition.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
#! /bin/bash
#create an aaray to carry the select options
options=( "Create_Database" "List_the_Databases" "Connect_to_a_Database" "Remove_a_Database" "Exit")
# adusting the PS3
PS3="DB.Engin-> "
count=0
select opt in ${options[@]}
do
case $opt in
#special characters
"Create_Database" )
#echo "please create a db"
#write the code of the creation
read -p "Please enter the database name: " db_name
if [[ $db_name =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]
then
if [ -e ./$db_name ]
then
echo "already exist"
else
echo "Waiting until created"
sleep 1
mkdir ./$db_name
echo "Done"
fi
else
echo "not valid enter again"
fi
;;
"List_the_Databases" )
echo "These are all the dbs exist"
#write the code of listing
ls ./
;;
"Connect_to_a_Database" )
echo "connect to a db"
#write the code of the connection
select connect_opt in ${connect_optoions[@]}
do
case $connect_opt in
"create_table" )
read -p "please enter the student id >> primary key" x
read -p "please enter student full name" y
read -p "please enter student age" z
echo "${X}:${y}:${z}" >> student.metadata
;;
"select_table" )
;;
"drop_table" )
;;
*)
;;
esac
done
;;
"Remove_a_Database" )
echo "remove this db"
#write the code of to delete
read -p "Please enter the database name: " db_name
#if [[ `find ./$db_name` == "./$db_name" ]] error because if not found find return nothing
if [[ -e ./$db_name ]]
then
echo "removing it ..."
sleep 1
rm -r ./$db_name
echo "Done"
else
echo "Not found"
fi
;;
"Exit" )
echo "bye bye"
break
;;
* )
# this a task for you abdelaziz here we need to write a code to do the following
#if the user entered an invalid optin for three times the script exist
((count++))
if [[ $count -eq 3 ]]
then
echo " you have entered invalid option many times!!"
exit 1
else
echo " $REPLY is invalid option!! \n please enter the a valid option"
fi
;;
esac
done