Assignment 3 Telephone book Solution

Implement in shell a "telephone book" program, which works according to the description given below (lines starting with "--" are comments, user inputs are in bold face, programs responses are in lower case. In the actual execution, user commands can be in lower/upper case). Note: do not use tools such as sed or awk, only standard shell. 

$ book 
~/misc/book doesn't exist, do you want to create one (y/n)? y 

response on the same line. If ~/misc/book already exists, the execution starts from the menu as given below: 


~/misc/book created -- or nothing if it already exists 

There are 5 users on the system -- or 3, or 1, etc 

Available commands: 

1.    Look someone up

2.    Add someone to the phone book

3.    Remove someone from the phone book

4.    List all names and numbers in the phone book

5.    Change the prompt

6.    See the menu

7.    Exit the program

Please select one of the above (1-6): 2 

Type in your entry, terminate with a single RETURN on the line: 

STEVEN BARK 

778 MAIN STREET 

WOLFVILLE 

542-2201 

Steven Bark added to the book 

: 5 -- Menu is not shown, ":" is a prompt 

Type in your new prompt: Yes my dear : 

Yes my dear: 5

Type in your new prompt: -- just RETURN, to use default prompt 

: 8 

? -- book doesn't know it 

: 2 

Type in your entry, terminate with a single RETURN on the line: 

STEVEN LONG 

118 UNKNOWN STREE T 

KENTVILLE 

678-2201 

: 6

Would you like to: 

1.    Look someone up

2.    Add someone to the phone book

3.    Remove someone from the phone book

4.    List all names and numbers in the phone book

5.    Change the prompt

6.    See the menu

7.    Exit the program

Please select one of the above (1-6): 1

Enter name to look up: LONG 

There is 1 item(s): 

#1: 

STEVEN LONG 
118 UNKNOWN STREET 
KENTVILLE 
678-2201 

: 1 

Enter name to look up: 2201 

There is 2 item(s): 

#1: 

STEVEN LONG 
118 UNKNOWN STREET 
KENTVILLE 
678-2201 

#2: 

STEVEN BARK 
778 MAIN STREET 
WOLFVILLE 
542-2201 

: 3 

Enter name to remove: 542 

There is 1 item(s): 

STEVEN BARK 
778 MAIN STREET 
WOLFVILLE 
542-2201 

Do you want to remove it? (y/n): Y 

: 7 



Hand in the source and the script of the execution. 

Hint. The shell procedure shown below displays the number of lines in the file whose name is passed on the command line 

a=0 
while real line 
do 

a=`expr $a + 1` 

done < $1 
echo "Final line count is: $a"

 
Powered by