Find the answer to your Linux question:
Results 1 to 2 of 2
Hello all. I'm having trouble with this program used to delete and rebuild files. I need to stop inputting into the file when the null "quit" is entered. Also my, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    9

    redirecting input to a file -- not exiting when "null" entered


    Hello all. I'm having trouble with this program used to delete and rebuild files. I need to stop inputting into the file when the null "quit" is entered. Also my, "Added...." , only displays every other input. I'm guessing my counter is only adding every other input also.
    Here's the section...

    echo -n "Would you like to rebuild file?"
    read reply

    case "$reply" in
    [Yy]* )
    echo "Start inputing information..."
    while [[ "$line" != "QUIT" || "$line" != "quit" ]]
    do
    read line
    line >> $f
    echo "Added..."
    count=$[$count +1]
    done
    echo "You have ""$count" "lines in the file."
    exit
    ;;
    [Nn]* )
    echo "Ok. Goodbye."
    rm "$f"
    exit
    ;;
    * )
    echo "You must enter YES or NO!"

    ;;

    esac

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    211
    hi

    what do you think `line >> $f` does ?

    you need to read line before testing it against QUIT or quit.

Posting Permissions

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