[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why `echo -n hello | while read v; do echo $v; done' prints nothing?
From: |
Clark J. Wang |
Subject: |
Re: Why `echo -n hello | while read v; do echo $v; done' prints nothing? |
Date: |
Fri, 3 Dec 2010 10:02:03 +0800 |
On Thu, Dec 2, 2010 at 11:49 PM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> On Thu, Dec 02, 2010 at 07:04:57PM +0800, Clark J. Wang wrote:
> > Following command also prints nothing, confused :(
> >
> > for ((i = 0; i < 10; ++i)); do echo -n " $i"; done | while read v; do
> echo
> > $v; done
>
> 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?
--
Clark