read builtin returns an exit status of 0 if it successfully reads any data. It has a nonzero exit status when it reaches the EOF (end of file).
The following example runs a while loop from the command line. It takes its input from the names file and terminates after reading the last line from names.
$ cat names
John Q. Public
$ while read first rest
> echo $rest, $first
> done < names
Q. Public, John
The placement of the redirection symbol (
<) for the while structure is critical. It is important that you place the redirection symbol at the done statement and not at the call to