Re: When reading less than wanted characters, "read" does not detect NUL bytes

2018-06-15 Thread Davide Brini
On Fri, 15 Jun 2018 15:15:23 +0200, Davide Brini wrote: > So it looks like the only "reliable" way to detect NULs in the input is to > read one character at a time. Your explanation got me thinking, and I've come up with the following code that seems to be slightly more efficient than reading on

Re: When reading less than wanted characters, "read" does not detect NUL bytes

2018-06-15 Thread Davide Brini
On Fri, 15 Jun 2018 09:07:46 -0400, Greg Wooledge wrote: > On Fri, Jun 15, 2018 at 03:03:21PM +0200, Davide Brini wrote: > > $ printf 'a\x00\x00bc' | { while IFS= read -d '' -n 2 var; do echo > > "read: $var, length: ${#var}"; done; } read: a, length: 1 > > read: , length: 0 > > read: bc, length:

Re: When reading less than wanted characters, "read" does not detect NUL bytes

2018-06-15 Thread Greg Wooledge
On Fri, Jun 15, 2018 at 03:03:21PM +0200, Davide Brini wrote: > $ printf 'a\x00\x00bc' | { while IFS= read -d '' -n 2 var; do echo "read: > $var, length: ${#var}"; done; } > read: a, length: 1 > read: , length: 0 > read: bc, length: 2 > > I would expect there to be another read of length 0 betwee