Results 1 to 3 of 3

Thread: Help with read command

  1. #1
    Join Date
    Feb 2013

    Help with read command

    I'm having trouble with the read command. So I want to keep asking the user to keep entering values but once the user stops I have to stop.

    I was thinking of doing while [ true ]
    but then I need to know when the user stops. I heard pressing ctrl -d works on stdin but it's not working.

    any suggestion.

    oh and I can't have the user press any key to exit.

  2. #2
    Join Date
    Feb 2009
    Dallas, TX
    Ubuntu 14.04 Trusty Tahr

    Re: Help with read command

    Hi toad3000.
    Quote Originally Posted by toad3000 View Post
    I heard pressing ctrl -d works on stdin
    That is correct. But not in the middle of a line, just as the only character press on an empty line.

    'read' itself can be use on the while condition as is returns true when a line is read, and false when it gets a EOF (end of file).

    This would work as you intent:
    while read line; do
    Hope it helps. Let us know how it goes.

  3. #3
    Join Date
    Feb 2013

    Re: Help with read command

    Hey thanks a lot! I didn't know that read returns a true or false. Thank you. This clears up so much!


Posting Permissions

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