Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    need help with this script please

    hey how r ya guys ... I was trying to solve this problem but im really sure that I didnt get to the right answer yet , I posted my attempt so if anyone would help me looking at it and give some corrections thank u

    write a script that will :
    a) given the file name last_names exists in the current directory
    b) use a loop to prompt for 5 text lines that the user can enter last name on
    c) if the name entered is not in the file then add it to the file
    echo -n "Enter 5 last names"
    read guess
    for guess in 1 2 3 4 5
    echo -n "Enter another last time: "
    read name
    if [ "$guess" -ne "$last_name" ]
    echo "$guess" >> "$last_name"
    echo "ok."

  2. #2
    I'm not exactly sure what you're trying to do, but is this what you mean?
    # the file containing last names
    # make sure the file exists, or quit
    ! [ -f $last_name ] && echo "$last_name: File not found" && exit 1
    # loop thru 5 times
    for guess in 1 2 3 4 5; do
      # get last name from user input
      read -p  "Enter last time #$guess: " name
      # look in the last name text file for the name entered
      cat $last_name|grep -q ^$name$
      if [ $? -ne 0 ]; then
        # if not found, append the name to the file list
        echo "$name" >> "$last_name"
        # otherwise, indicate that it was found
        echo "name $name found."

  3. #3
    thank you so much I got it working now ... appreciate ur help!!

  4. $spacer_open

Posting Permissions

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