-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddr.sh
More file actions
71 lines (60 loc) · 1.83 KB
/
addr.sh
File metadata and controls
71 lines (60 loc) · 1.83 KB
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
#!/bin/bash
echo
echo Bash Addressbook! Welcome to the bash addressbook and thanks for trying it out!
echo
while [ "$operation" != "q" ]; do
echo What operation would you like to do?
echo Choose between $(tput setaf 2)ADD$(tput sgr0), $(tput setaf 7)DISPLAY$(tput sgr0), FIND, $(tput setaf 1)REMOVE$(tput sgr0) and Q:
read operation
case $operation in
# echo ======================================================================================
"add")
echo $(tput setaf 2)ADD$(tput sgr0) has been selected.
echo Please enter the first name:
read firstName
echo Please enter the last name:
read lastName
echo $firstName $lastName >> contacts.txt
echo $firstName $lastName has been added to the addressbook.
;;
"display")
echo $(tput setaf 7)DISPLAY$(tput sgr0) has been selected.
echo
if [ -f ${PWD}/contacts.txt ]; then
cat contacts.txt
else
echo Addressbook empty or not found.
fi
;;
"find")
echo FIND has been selected
echo Enter first or last name:
read firstLast
if grep -qR "$firstLast" contacts.txt ; then
echo "$firstLast" was found in the address book.
else
echo "$firstLast" could not be found in the address book.
fi
;;
"remove")
echo $(tput setaf 1)REMOVE$(tput sgr0) has been selected:
echo Please enter the first and last name of the contact that you wish to remove:
read firstLast2
if grep -qR "$firstLast2" contacts.txt ; then
echo "$firstLast2" was found in the address book.;
sed "/$firstLast2/d" < contacts.txt > contacts.txt
# sed "/$firstLast2/d" contacts.txt
echo "$firstLast2" has been removed.
else
echo "$firstLast2" could not be found in the address book.
fi
;;
"q")
echo Thanks for using Addressbook
;;
*)
echo Not a valid command
;;
esac
echo ======================================================================================
done