bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: read builtin return non-zero status reason


From: Greg Wooledge
Subject: Re: Fwd: read builtin return non-zero status reason
Date: Wed, 24 Feb 2016 10:05:51 -0500
User-agent: Mutt/1.4.2.3i

On Wed, Feb 24, 2016 at 09:45:02PM +0700, Cuong Manh Le wrote:
> If you put it into a while loop context:
> 
> while read -d '' line; do echo "$line"; done < <(printf '1')
> 
> 
> give you nothing. There's only one read in this case
> 
> There's data to read, but read return non-zero there. it doesn't find
> delimiter, does it?

It encounters EOF before it reads the delimiter.  So, you can say "it
returned nonzero because it encountered EOF", or "it returned nonzero
because it didn't read the delimiter", or "it returned nonzero because
the delimiter is missing".  They all mean the same thing.

P.S. in this case, the value 1 is in the variable line, even though read
returned nonzero.  You *do* get the partial line.

> Compare to:
> 
> while read -d '' line; do echo "$line"; done < <(printf '1\0')
> 
> 
> give you 1. There two read, the first *read* 1, the second reached EOF,
> cause the while loop terminated.

The while loop terminates *because* read returns nonzero, not the other
way around.  Otherwise, that's correct.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]