Find the answer to your Linux question:
Results 1 to 7 of 7
I could use some help inwriting this script - I know it is a loop but am having trouble: I need a script that will prompt for the user’s first ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    11

    desperate need some help with script

    I could use some help inwriting this script - I know it is a loop but am having trouble:

    I need a script that will prompt for the user’s first name and store it in a variable. Then prompt for the last name and store it in a variable. Finally, display the stored information in the format “You entered lastname, firstname” and ask the user for confirmation. If the answer is “y” or “yes” then say “Thank you!” if the answer is “n” or “no” then start again with the prompts.

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    7
    Are you wanting to do this with Bash/Perl/C?

  3. #3
    Just Joined!
    Join Date
    Feb 2009
    Posts
    11
    iam using puppy linux

  4. #4
    Just Joined!
    Join Date
    Feb 2009
    Posts
    11
    yes bash is ok

  5. #5
    Just Joined!
    Join Date
    Feb 2009
    Posts
    11
    so far i have :

    #!/bin/bash
    declare FName
    read -p "enter first name" : "$Fname
    declare LName
    read -p "enter last name" : "$Lname

  6. #6
    Just Joined!
    Join Date
    Feb 2009
    Posts
    11
    actually i have this now:

    #!/bin/bash
    declare FName
    read -p "Enter First Name : " FName

    declare LName
    read -p "Enter Last Name : " LName
    echo "you entered" $FName $LName
    echo "is that correct?"

  7. #7
    Just Joined!
    Join Date
    Feb 2009
    Posts
    7
    I must admit I'm not fantastic with bash scripting, but this is what I came up with:

    Code:
    #!/bin/bash
     
    function readName {
        read -p "Enter first name: " FName
        read -p "Enter last name: " LName
        echo "You entered $FName $LName"
        read -p "Is this correct (y or n)?" valid
    
        if [ $valid = "y" ]; then
            echo "correct!"
        else
            readName
        fi
    }
    
    readName
    Edit: Edited out a hyphen that copied over from vim

Posting Permissions

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