Linux Shell Scripting [Introduction to Linux using awk, sed, vi, if elif else, c
ID: 3783315 • Letter: L
Question
Linux Shell Scripting [Introduction to Linux using awk, sed, vi, if elif else, cut, pipes etc] (no array, no grep)
Write a menu for a phone book system. A- Enter contact information B- Search using a name C- Search using phone number D- Exit Use case statement for reading choices. If choice A is selected then run another script to read contact information. If Bis selected run another script that search using a name. If C is selected run another script to search using phone number. Script for part-A: clear the screen and display: 1- First Name 2- Last Name 3- Phone 4- Email: 5- Exit Store all information in a file and repeat asking the same questions unless the user selects Exit. Then yo should go back to the main menu Script for part-B: Read the name and use awk to search in the file for the given name and display the phone number of that person Script for part-C: Read the phone and use awk to search in the file for the given phone and display the email and name of that person.Explanation / Answer
# echo "Book = $BOOK"
echo -e " ======== Beginning Adding Addresses ======= "
# Ask the user for a name and assign to a variable
echo -n "Name of person: "
read name
# Ask for the street address
echo -n "Street Address: "
read street
# Ask for the city
echo -n "City: "
read city
# Ask for the state address
echo -n "State: "
read state
# Ask for the zip address
echo -n "Zip Code: "
read zip
# Ask the user for a phone number and assign to a variable
echo -n "Phone number: "
read phone
# Echo the answers and ask for confirmation
echo "Should I enter the values:"
echo -e " $name $street $city, $state, $zip $phone "
echo -n "y/n: "
read answer
# Convert the answer to lower case
fixedanswer=`echo $answer | tr "A-Z" "a-z"`;
if [ "$fixedanswer" = "y" ]
then
# Write the values to the address book
echo "$name;$street;$city;$state;$zip;$phone" >>$BOOK
echo "Added the entry OK"
sleep 5
else
# Give the user a message
echo -e " $name $street $city, $state, $zip $phone NOT written to $BOOK"
sleep 5
fi
exit 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.