Telephone book script | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Telephone book script

Homework & Coursework Questions


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-18-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Telephone book script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Hi, here is my other assignment for the week.

Create a shell script for a telephone book application. Display a menu for the following functions.

1. Add an entry----done
2. Display all matches to a string----done
3. Sort and display the file
4. Delete all entries that match a string----done
5. exit the program

Using the phone list below:

Add a new name to the phone book file
Display all matches to a name or phone number
Sort the phone book file by last name
Delete an entry

Print the results from each sequence of commands

Data File (tabs between fields)
Gene Smith 732 946-4691
Henry Brown 908 922-5820
Harry Crown 609 566-4515
Jim Zark 732 842-1910
Tom Mann 908 264-5321
Jack Spratt 908 264-4816
Joe Bram 609 521-4841



2. Relevant commands, code, scripts, algorithms:

shell programming

3. The attempts at a solution (include all code and scripts):


Code:
#!/bin/sh
    # Name of phonebook
    BOOK="phonebook.txt"

    exit=0

    while [ $exit -ne 1 ]
    do
        echo "operation you want?"
        echo -e "add, list, find, delete, exit: "
        read answer

        if [ "$answer" = "add" ]
        then
            ./add.sh
        elif [ "$answer" = "list" ]
        then
            ./list.sh
        elif [ "$answer" = "find" ]
        then
            ./find.sh
        elif [ "$answer" = "delete" ]
        then
            ./delete.sh
        elif [ "$answer" = "exit" ]
        then
            exit=1
        else
            echo "command not available."
        fi
    done

    exit 0

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Brookdale Community College - Lincroft, New Jersey - United States - Dr. Rick Bournique- COMP 145


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Sponsored Links
    #2  
Old 04-19-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 September 2014, 4:01 PM EDT
Location: Switzerland - GE
Posts: 5,711
Thanks: 156
Thanked 400 Times in 375 Posts
Have you heard of case statement?
Do a bit of googling and look around in our forums...
Sponsored Links
    #3  
Old 04-21-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
I understand that the case statement will be cleaner, but is this not valid? (e.g. does it accomplish what my teacher wants)?
    #4  
Old 04-21-2013
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 Posts
I tried your master script. It seems to work fine, seems to accomplish what your teacher wants. I did notice (minor nit-picky) that the "echo -e" prints the -e instead of using it as a command option. I won't explain why it does that, according to the forum rules.
Sponsored Links
    #5  
Old 04-21-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
I have been trying to replicate this with a case statement because I am not sure which way he wants this. He has an example of creating a menu in our powerpoint slides, so he might want us to do it that way, but I cannot figure out how to add the commands properly. Would it be something like:


Code:
# Use of a case statement to offer a 5 item menu
echo “  Menu\n1. Add an entry \n2. Display all matches to a string\n3. Sort and display the file\n4. Delete all entries that match a string\n5. Quit to Unix\nEnter your option #: \c”
read choice
case “$choice” in
	1) add;;
	2) list;;
	3) find;;
	4) delete;;
	5) exit ;;
	*)	echo “Invalid option”   # ;; not needed for last option
esac

I am not sure how to add the commands properly like I did with the original solution, where I included the sub scripts like ./add.sh. Any ideas?
Sponsored Links
    #6  
Old 04-21-2013
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 Posts
As you said, I think the teacher just wants something that works. You could ask the teacher if case is preferable, or is OK to use if / else.
Sponsored Links
    #7  
Old 04-21-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Cool he said if / else is fine.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Got connected with Modem but cannot dial Telephone no. to connect to host abidmalik UNIX for Dummies Questions & Answers 1 01-06-2003 02:12 PM
all about telephone in unix radheesh IP Networking 1 11-20-2002 09:31 AM
telephone working in unix radheesh UNIX for Dummies Questions & Answers 1 11-19-2002 06:37 PM



All times are GMT -4. The time now is 07:35 PM.