If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help required on basic Unix Bourne Shell Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-10, 06:15
methopoth methopoth is offline
Registered User
 
Join Date: Mar 2010
Posts: 3
Lightbulb Help required on basic Unix Bourne Shell Script

Howdy People

I'm a newbie & its my first question here. I've started learning Unix Bourne Shell scripting recently and struggling already Can someone PLEASE help me with the following problem. Somehow my script is not working.

* Display an initial prompt of the form:
Welcome to machine name. What is your name?
where machine name is the network name for the machine that the script is running on.
* Read the name that the user enters
* Respond with the output:
Hello name, how are you?
* Read the response from the user
* If the response contains the word “good” respond with:
I’m glad to hear that.
* Otherwise, respond with:
I’m sorry to hear that. Hope you feel better soon.
* Finally output: Good-bye.


Much appreciated guys. Thanks heaps in advance
Reply With Quote
  #2 (permalink)  
Old 03-25-10, 08:40
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
What have you done so far?
Reply With Quote
  #3 (permalink)  
Old 03-25-10, 08:54
methopoth methopoth is offline
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks for your reply. This is wat i've done so far:

echo -n "Welcome to `hostname`. What is your name? "
read LINE
echo -n "Hello ${LINE}, how are you? "
read LINE
if test "${LINE}" = "good"
then
echo "I'm glad to hear that."
else
echo "I'm sorry to hear that. Hope you feel better soon"
fi
echo "Good-bye."
Reply With Quote
  #4 (permalink)  
Old 03-25-10, 09:29
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
And what happened when you tried running this script?

PS obviously you won't get your homework done for you on the forum.
__________________
Mike
Reply With Quote
  #5 (permalink)  
Old 03-25-10, 09:46
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Your script works if the answer to "how are you" is "good".
The problem is with the if statement.
There is no test for a variable containing a substring.

Two hints.

grep will find a string within a string
$? is 0 if the previous command was successful.
Reply With Quote
  #6 (permalink)  
Old 03-25-10, 10:05
methopoth methopoth is offline
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks again for your reply Kitaman. Legend!
mike_bike_kite aka vaguely human, Homework??!! I'm homeless dude.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On