Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    Lightbulb Unanswered: 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:
    Im glad to hear that.
    * Otherwise, respond with:
    Im sorry to hear that. Hope you feel better soon.
    * Finally output: Good-bye.


    Much appreciated guys. Thanks heaps in advance

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    What have you done so far?

  3. #3
    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."

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    And what happened when you tried running this script?

    PS obviously you won't get your homework done for you on the forum.

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    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.

  6. #6
    Join Date
    Mar 2010
    Posts
    3
    Thanks again for your reply Kitaman. Legend!
    mike_bike_kite aka vaguely human, Homework??!! I'm homeless dude.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •