LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2005, 05:35 PM   #1
Grooveyphreak
LQ Newbie
 
Registered: May 2005
Distribution: Fedora Core 2
Posts: 19

Rep: Reputation: 0
need help on a shell script


Okay I know we are not supposed to post asking for help on school assignments but this is just a project out of my book that i have to complete and the professor is never available he is a sudo prof. part timer. anyway i've got to create the follwing in the vi editor

#!/bin/bash
echo -e "what would you like to do?
add an entry (a)
search and entry (s)
enter your choice (a/s)-->\c"
read ANSWER
case $ANSWER in
a|A ) echo -e "Please enter the name... --> \c"
read NAME
echo -e "Please enter relation... --> \c"
read RELATION
echo -e "Please enter phone number --> \c"
read PHONE
echo "$NAME\t$RELATION\t$PHONE" >> database
s|s ) echo "what word would you like to look for? --> \c"
read WORD
grep "$WORD" database
*) echo "you must enter either the letter a or s."
esac

my question is when i enter all this in and enter the ./myscript2 to run it
no matter what i enter i get a syntax error on the ) in the s|S ) also when entering this in the vi editor the first ) symbol turns orange and the latter stays white as if it's not recognizing it as a director. given the information and the "code" above what am i doing wrong it's written in the text book and i've followed it word for word and it still doesn't work i have emailed my prof but more than likely will not her from him till next week this is due in by the end of the day friday. someone please reply soon as I won't have internet at my house till tuesday next week and i'm at a friends house only for a short time tonight. major thanks in advance for any help.
 
Old 06-16-2005, 05:43 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Since it's an assignment I'll not give the answer but point you to a good explanation of the syntax for "case" statements
http://www.tldp.org/LDP/Bash-Beginne...ect_07_03.html
 
Old 06-16-2005, 05:54 PM   #3
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
You need to change a few things. I can't believe that code was in a book. Is the idea
that your suppose to correct the errors in the code? I'll give you some hints.
;; // double semicolons are important for case statements
"" // Not 100% sure it's required but you should quote your cases like
"a" | "A"

EDIT: You should check the "s" case as well. Something is not right there as well.

Hope that helps.

Zack

Last edited by zackarya; 06-16-2005 at 05:57 PM.
 
Old 06-16-2005, 05:54 PM   #4
Grooveyphreak
LQ Newbie
 
Registered: May 2005
Distribution: Fedora Core 2
Posts: 19

Original Poster
Rep: Reputation: 0
ok i think i get the gist of what that link was stating but the text says edit the script so that it reads exactly as i wrote it with no ;; anywhere in it. and only one instance of case so i'm a little perplexed as to why it's not working
oh yeah to clearify it's not an "assignment" persay it's more of an excersice at the end of a chapter we get 1 point for doing them. didn't want people to think I was cheating.

with the exception of the ...'s i just put those in as instead of blah blah blah
what has me so confused is that the top a|A ) works with no syntax error and but the latter just won't work unfortunately i'm 30 mins away from home and linux isn't installed on this computer so unable to check and reply with results this is really frustrating cause my professor is never around to speak with. so i'm usually left with no explanation.
 
Old 06-16-2005, 05:59 PM   #5
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
Ummm, the assignment says to use case but to not use it correctly? You HAVE to have
;; "double semicolons" for the case statement to work in the first place.

Not sure why they would tell you not to use them as I don't think that there is anyway to
use case without them.

Zack
 
Old 06-16-2005, 06:05 PM   #6
Grooveyphreak
LQ Newbie
 
Registered: May 2005
Distribution: Fedora Core 2
Posts: 19

Original Poster
Rep: Reputation: 0
so if they have to be in place i assume i throw them at the last | ) or would it go after the *) thing i was hoping that was the case that the book was wrong it's funny i just looked back thru the chapter and no where in it does it say anythign about ;; great i'm learning from a book that is incorrect and this is from an acredited school albeit a comm college but none the less acredited

like i said i really appriciate the help i get on here.
 
Old 06-16-2005, 06:08 PM   #7
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
I can't be sure but maybe the book was written for some other shell that uses a different
syntax than bash.

As for the ;; it's used to seperate your case statements so you'll need them in 3 places.

Hope that helps.

Zack
 
Old 06-16-2005, 06:12 PM   #8
Grooveyphreak
LQ Newbie
 
Registered: May 2005
Distribution: Fedora Core 2
Posts: 19

Original Poster
Rep: Reputation: 0
i don't think it does cause it says use #!/bin/bash
anyway thanks for the help

btw you said use in three spots which is fine but the first ) works it's only the second that doesn't why is that or are there just some things we shouldn't question.
 
Old 06-16-2005, 06:32 PM   #9
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
What is it about the second one that doesn't work?
Does it crash out of the program or does'nt work the way you expected?

Post the updated code that you have so I can see where your at and I'll see
if I can see the problem.


Zack
 
Old 06-18-2005, 12:18 AM   #10
Grooveyphreak
LQ Newbie
 
Registered: May 2005
Distribution: Fedora Core 2
Posts: 19

Original Poster
Rep: Reputation: 0
well i got it to work i had to try it i'll post the script tuesday just to show my work god tuesday can't come soon enough
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 07:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-12-2005 12:08 AM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 04:00 PM


All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration