0

Each time the read builtin is executed it parses the next line of the input, but where in the man page is this mentioned? How would I know this beforehand?

EDIT I guess @dirkt answered this.

3

From man bash:

read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]

One line is read from the standard input, [...]

It's in the section labeled SHELL BUILTIN COMMANDS.

  • Yeah, I saw that, but does "read from stdin" mean that you are modifying stdin? – zagortenay333 Dec 7 '16 at 21:26
  • @zagortenay333 stdin by default refers to input from keyboard, so if you're reading from stdin it just means reading what you type in. Modifying stdin would mean reading from file or from pipe, so whatever text comes in from file or from pipe will be treated as input. See this for example: paste.ubuntu.com/23595339 The command is cat | while read line ; do echo "You said" "$line" ; done . I am typing in something to cat, and cat forwards it via pipe to read. By the way, while read line; do . . . done is very common way for reading multiline input – Sergiy Kolodyazhnyy Dec 7 '16 at 21:33
  • I know that.. What I don't understand is how the phrase "read one line from stdin" means that the next time I read it it will be the next line of the input. – zagortenay333 Dec 7 '16 at 21:35
  • The input here has multiple lines. – zagortenay333 Dec 7 '16 at 21:36
  • Reading is usually sequentially, and "consumes" what you've read from the source (or advances the file position, etc.) – dirkt Dec 7 '16 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.