On 12/02/2010 07:02 PM, Clark J. Wang wrote: >> The output from the first command in the pipeline does not end with a >> newline. Therefore, 'read' in the second command returns 'failure' >> (non-zero) when it reads the first line of input, and your loop never >> iterates. > > But is that reasonable? I think read should return success in this case > which makes more sense to me. Does the POSIX standards require that?
POSIX requires that the input to read be a text file (and by the definition of text file in POSIX, it must either be empty or end in a newline). By violating POSIX and passing something that does not end in a newline, you are no longer bound by the rules of POSIX. Therefore, it would be a reasonable bash extension that read could return 0 status if it read data that did not end in a newline, but it would not be a standard-compliant script that relied on such an extension. You're better off supplying the trailing newline, and guaranteeing a compliant usage. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature