Sponsored Content
Homework and Emergencies Homework & Coursework Questions Problem with executing a possible if or case statement script Post 302522309 by Rgasin02 on Saturday 14th of May 2011 09:58:41 AM
Old 05-14-2011
Question Problem with executing a possible if or case statement 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:
Create a phonebook program.
It should use functions to perform the required tasks. It should be menu-based, allowing you the options of:

* Search address book
* Add entries

You will also need a Display function to present the result.
Suggestions:
The phonebook is basically an ASCII file with Phone Number, Name, Email Address and zipcode.
Try to use ":" as field seperator [IMG]file:///C:/DOCUME%7E1/ROBERT%7E1/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image002.gif[/IMG]



2. Relevant commands, code, scripts, algorithms:
I would think to use either case and if statements together, trying to nest them, or possibly using a loop of some kind, but I haven't gotten the whole loop thing down.
I know that i havent incorporated the phone list into it yet, but i just want my scripting to work. Not sure if I'm reading the problem correctly either.

3. The attempts at a solution (include all code and scripts):
GNU nano 1.2.4 FileSmiliehonebook

Code:
# ==================================================================================================
# Title: Phonebook directory
# Owner: Rob 
# Purpose: To allow the user to look up directories in the file
# ==================================================================================================

printf "Who would you like to search for in our database? \n"

printf "Enter your option for a record: \n a: add \n s: search \n e: exit \n"; read option
 case "$option" in
   "a") echo "A new record will be added.";;
   "s") echo "You have chosen to search the directory";;
   "e") echo "You have chosen to exit the database. Goodbye..";;
   *) echo "That is an invalid option.";;
if [ "$option" = "s" ]
then
   echo "`more phonelist`"
else
   if [ "$choice" = "a" ]
then
   echo "input the name of the person you would like to add"
else
   if [ "$chioce" = "e" ]
then
   echo "you have chosen to leave the database. Goodbye..."
else
   echo "That is an invalid option"
fi
fi
fi
 esac

Here is the phonebook directory

GNU nano 1.2.4 File: phonelist

Code:
Directory of local Clients and their information

907-345-0962 : Essie Vaill       : essie@vaill.com       : 99515
602-252-4237 : Cruz Roudabush    : cruz@roudabush.com    : 85004
212-889-5775 : Billie Tinnes     : billie@tinnes.com     : 10001
732-442-0638 : Zackary Mockus    : zackary@mockus.com    : 88761
808-836-8960 : Rosemarie Fifield : rosemarie@fifield.com : 96819
815-467-0487 : Bernard Laboy     : bernard@laboy.com     : 60410
602-953-2753 : Sue Haakinson     : sue@haakinson.com     : 85051
610-395-8745 : Valerie Pou       : valerie@pou.com       : 18087
626-960-6738 : Lashawn Hasty     : lashawn@hasty.com     : 91790
407-857-0431 : Marianne Earman   : marianne@earman.com   : 32809
901-327-5336 : Justina Dragaj    : justina@dragaj.com    : 38112
503-371-8219 : Mandy Mcdonnell   : mandy@mcdonnell.com   : 97302
330-758-0314 : Conrad Lanfear    : conrad@lanfear.com    : 44512
714-772-5050 : Cyril Behen       : cyril@behen.com       : 49202
210-229-3017 : Shelley Groden    : shelley@groden.com    : 78205

The names and likenesses are all made up, but for the sake of the assignment they are there.




4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Baker College, Jackson, MI, USA, S.Sadiq LUX 211

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).

Last edited by pludi; 05-16-2011 at 04:27 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Case statement problem

I need to display this menu and accept variables. Can someone tell me why i am having a problem with this case statement, please # TAPE MANAGER MAIN MENU tapemgr_Main_Menu() { echo "Legato Tape Management System Menu" echo " This system is used to report Legato ERV Offsite and Tapes... (6 Replies)
Discussion started by: gzs553
6 Replies

2. Shell Programming and Scripting

what is problem with this small shell script.. case statement related

Hi All, this small script is written to recognize user input character.. it is in small case .. upeer case or is a number... but when i input first capital letter say A.. it always gives small character.... what is the problem. #!/bin/bash echo "Enter the character" read a case $a in )... (2 Replies)
Discussion started by: johnray31
2 Replies

3. Shell Programming and Scripting

shell script case statement

In a case statement like below : case $rental in "car") echo "For $rental Rs.20 per k/m";; "van") echo "For $rental Rs.10 per k/m";; "jeep") echo "For $rental Rs.5 per k/m";; "bicycle") echo "For $rental 20 paisa per k/m";; *) echo "Sorry, I can not gat a $rental for you";;... (4 Replies)
Discussion started by: sriram003
4 Replies

4. Shell Programming and Scripting

Problem with case statement

Hi, I need modify the all lines in a file into one format. cat file htec.twe34c.ATI .hesh.twdghu..ATI ..hesh.twdghu..ATI htec.twe3 hjsct14567ati Output should have 16 characters htectwe34c ATI heshtwdghu ATI heshtwdghu ATI htectwe3 ATI hjsct14567 ATI (4 Replies)
Discussion started by: kartheek
4 Replies

5. Shell Programming and Scripting

Problem with CASE statement

Guys, Here is the script syntax which is not accepting the parameters & not performing the said activity. $ ./routing.sh xyz123-ra str enable ********************************************************************** Preparing to service the request for Device xyz123-ra in Question... (9 Replies)
Discussion started by: raghunsi
9 Replies

6. Shell Programming and Scripting

Problem using 'Case' statement

Hi, When I execute the below script, I am getting the error as ' is not expected.ror at line 3 : `in #!/bin/sh case $1 in -r) echo Force deletion without confirmation ;; -i) echo Confirm before deleting ;; *) echo Unknown argument ;; esac I could not see any problem with... (1 Reply)
Discussion started by: Sathish_Obla
1 Replies

7. Shell Programming and Scripting

Help With Loop in Case Statement script

I am writing a bash script that asks the user for input and I need it to repeat until the user selects quit.. I dont know how to write the loop for it I searched all over but i still do not get it.. if anyone could help with this it would be greatly apprciated here is my script so far: #!... (2 Replies)
Discussion started by: Emin_Em
2 Replies

8. Shell Programming and Scripting

Problem using bash case statement

I have the following bash script and it is not accepting the lines "--"|"--""-") "--""-"") while do echo "Current Argument is ${1}" case "$1" in "--"|"--""-") echo "Argument is ${1}" shift # Skip ahead one to the next argument. ... (1 Reply)
Discussion started by: kristinu
1 Replies

9. Shell Programming and Scripting

Case Statement for Login/Logoff Script

I'm currently trying to write a login script. I have already written a logoff script that uses an if/else statement. #!/bin/bash TIMED=$(date +%H) if ' then echo Have a Great Day $USER else echo Have a Great Night $USER fi But I'd like to write one that give me the option of... (1 Reply)
Discussion started by: bbowers
1 Replies

10. Shell Programming and Scripting

[Solved] Strange Problem in case statement while shift

Hi, Here is my code as below: test.ksh: ======= #!/bin/ksh option="${1}" while do case $1 in -f) FILE="${2}" echo "File name is $FILE" ;; -d) DIR="${2}" echo "Dir name is $DIR" ;; -*) echo "`basename ${0}`:usage: | " (5 Replies)
Discussion started by: zaq1xsw2
5 Replies
All times are GMT -4. The time now is 03:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy