You are on page 1of 11

A micro project report on

CREATE A PHONE DIRECTORY USING SHELL SCRIPT


WITH VARIOUS OPERATIONS IN IT
Submitted to CMR Institute of Technology in partial fulfillment of the requirement for the
award of laboratory Scripting Languages Lab of II B. Tech I semester

CMR INSTITUTE OF TECHNOLOGY


(UGC AUTONOMOUS)
(Approved by AICTE, Affiliated to JNTUH, Kukatpally, Hyderabad)

Kandlakoya, Medchal Road, Hyderabad (2022-2023)

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Submitted by

N.HYMA REDDY 22R01A0443

N.REVATHI CHOWDARY 22R01A0444

N.HIMA VENKAT SAI 22R01A0445

N.JAHNAVI 22R01A0446

Under the Guidance of


Dr.B.V.Krishnaveni
CMR INSTITUTE OF TECHNOLOGY
(UGC AUTONOMOUS)
(Approved by AICTE, Affiliated to JNTUH, Kukatpally, Hyderabad)

Kandlakoya, Medchal Road, Hyderabad (2022-2023)

2022-2023
DEPARTMENT OF ELECTRONICS AND COMMUNICATION

ENGINEERING

CERTIFICATE
This to certify that a Micro Project entitled with “CREATE A PHONE DIRECTORY
USING SHELL SCRIPT WITH VARIOUS OPERATIONS IN IT” is being

Submitted by

N.HYMA REDDY 22R01A0443

N.REVATHI CHOWDARY 22R01A0444

N.HIMA VENKAT SAI 22R01A0445

N.JAHNAVI 22R01A0446

In partial fulfilment of the requirement for award of the “Scripting Languages Lab” of II B.
Tech I semester in ECE to the CMRIT, Hyderabad is a record of a bonafide work carried out
under our guidance and supervision.

Signature of Faculty Signature of HOD

Dr.B.V.Krishnaveni Dr. K. Niranjan Reddy

(Head Of Department)
ACKNOWLEDGEMENT

We are extremely grateful to Dr. M. Janga Reddy, Director, Dr. B. Satya Narayana, principal
and Dr.K.Nirangan Reddy, Head of Department, Dept of computer Science and Engineering,
CMR Institute of their inspiration and valuable guidance during entire duration.

We are extremely thankful to our SL Lab faculty in-charge Dr.B.V.Krishnaveni, dept of


Electronics and Communication Engineering, CMR Institute of Technology for her constant
guidance, encouragement and moral support throughout the project.

We express our thanks to all staff members and friends for all the help and coordination
extended in bringing out this project successfully in time.

Finally, we are very much thankful to our parents and relatives who guided directly or
indirectly for successful completion of the project.

N.HYMA REDDY 22R01A0443

N.REVATHI CHOWDARY 22R01A0444

N.HIMA VENKAT SAI 22R01A0445

N.JAHNAVI 22R01A0446
ABSTRACT:
Phone Directory Shell Script

In the realm of shell scripting, the creation of a phone directory script offers a
practical and efficient solution for managing contact information. This project
introduces a shell script designed to perform various operations on a phone
directory, providing users with a streamlined interface to add, search, display,
and delete contacts.

INTRODUCTION:
The Phone Directory Shell Script is a simple command-line tool designed to
manage a phone directory. It allows users to perform basic operations such as
adding new contacts, searching for existing contacts, displaying the entire
directory, deleting contacts, and exiting the application.

Key Features:

User-Friendly Interface:

The script presents a clear menu interface for users to interact with various
operations.

Users can easily navigate through options to execute desired tasks.

Data Persistence:

Contact information is stored in a text file (phone_directory.txt) for persistent


usage.

Upon initialization, the script checks for the existence of the directory file,
creating it if not present.

Operations:

Add Contact:

Users can add new contacts by providing the name and phone number.

The information is appended to the phone directory file.


Search Contact:

Users can search for a contact by entering the name.

The script performs a case-insensitive search and displays the contact details if
found.

Display All Contacts:

The script allows users to view the entire phone directory, presenting a list of all
contacts.

Delete Contact:

Users can delete a contact by specifying the name.

The script removes the contact entry from the phone directory file.

Exit:

A graceful exit option allows users to conclude their interaction with the phone
directory script.

Usage:

Execute the script (./phone_directory.sh) to launch the phone directory


interface.

Follow the on-screen instructions to perform desired operations.

The script ensures data persistence across sessions, enhancing usability.

Objective:

The objective of this shell script is to create a simple phone directory


management system with various operations. The script allows users to perform
tasks such as adding new contacts, searching for existing contacts, displaying
the entire directory, deleting contacts, and exiting the application.
SOURCE CODE:
#!/bin/bash

phone_file="phone_directory.txt"

# Check if phone directory file exists, if not create it

if [ ! -e $phone_file ]; then

touch $phone_file

fi

# Function to add a new contact

add_contact() {

read -p "Enter name: " name

read -p "Enter phone number: " phone_number

echo "$name: $phone_number" >> $phone_file

echo "Contact added successfully!"

# Function to search for a contact

search_contact() {

read -p "Enter name to search: " search_name

grep -i "$search_name" $phone_file || echo "Contact not found."

}
# Function to display all contacts

display_contacts() {

echo "Phone Directory:"

cat $phone_file

# Function to delete a contact

delete_contact() {

read -p "Enter name to delete: " delete_name

sed -i "/$delete_name/d" $phone_file

echo "Contact deleted successfully!"

# Main menu loop

while true; do

echo "Phone Directory Operations:"

echo "1. Add a new contact"

echo "2. Search for a contact"

echo "3. Display all contacts"

echo "4. Delete a contact"

echo "5. Exit"

read -p "Enter your choice (1-5): " choice


case $choice in

1) add_contact ;;

2) search_contact ;;

3) display_contacts ;;

4) delete_contact ;;

5) echo "Exiting phone directory. Goodbye!"; exit 0 ;;

*) echo "Invalid choice. Please enter a number between 1 and 5." ;;

esac

read -p "Press Enter to continue..."

clear

done

ACTUAL OUTPUT:
Make the script executable:

chmod +x phone_directory.sh

Run the script:

./phone_directory.sh

Phone Directory Operations:

1. Add a new contact

2. Search for a contact

3. Display all contacts

4. Delete a contact

5. Exit
Enter your choice (1-5): 1

Enter name: John Doe

Enter phone number: 123-456-7890

Contact added successfully!

Press Enter to continue...

Phone Directory Operations:

1. Add a new contact

2. Search for a contact

3. Display all contacts

4. Delete a contact

5. Exit

Enter your choice (1-5): 3

Phone Directory:

John Doe: 123-456-7890

Press Enter to continue...

Phone Directory Operations:

1. Add a new contact

2. Search for a contact

3. Display all contacts

4. Delete a contact
5. Exit

Enter your choice (1-5): 2

Enter name to search: John Doe

John Doe: 123-456-7890

Press Enter to continue...

Phone Directory Operations:

1. Add a new contact

2. Search for a contact

3. Display all contacts

4. Delete a contact

5. Exit

Enter your choice (1-5): 4

Enter name to delete: John Doe

Contact deleted successfully!

Press Enter to continue...

Phone Directory Operations:

1. Add a new contact

2. Search for a contact

3. Display all contacts

4. Delete a contact
5. Exit

Enter your choice (1-5): 3

Phone Directory:

Press Enter to continue...

Phone Directory Operations:

1. Add a new contact

2. Search for a contact

3. Display all contacts

4. Delete a contact

5. Exit

Enter your choice (1-5): 5

Exiting phone directory. Goodbye!

CONCLUSION:
This phone directory shell script provides a practical solution for managing
contact information through a user-friendly interface. Its functionality,
combined with data persistence, offers a valuable tool for individuals seeking an
efficient and accessible method to organize and manipulate phone contacts.
Users can easily adapt and extend the script to suit specific needs, making it a
versatile and customizable solution in the realm of shell scripting.

REFERENCES:
 Bash Reference Manual "Unix and Linux System Administration
Handbook" by Evi Nemeth, Garth Snyder, Trent R. Hein, and Ben
Whaley.
 "Learning the bash Shell" by Cameron Newham and Bill Rosenblatt.

You might also like