On Wed, Nov 23, 2011 at 09:03:33AM -0500, Matthew Story wrote: > Description: read terminates reading all records at first null-byte ( chr(0) > ) in a stream, null-bytes are valid ascii characters and should not cause > read to stop reading > a line this behavior is not reproducible using bourne shell.
Actually, read does not stop reading at a NUL byte unless you tell it to by using -d ''. It reads until the newline. > Steps To Reproduce: > > [bash ~]$ printf 'foo\0bar\n' | while read line; do echo "$line"; done > foo What happens here is bash reads until the newline, but only the "foo" part is visible in the variable, because the NUL effective ends the string. Whether the "bar" part is copied into memory or not is not relevant and cannot be determined without poking around inside the bash process itself. If bash had actually stopped reading at the NUL, then the "bar" part would still be sitting there on stdin waiting for the next read. But we can see that this is not the case: $ printf 'foo\0bar\n' | { read line; echo "$line"; read line; echo "$line"; } foo $ The second read gets nothing. If we want to see bash stop at the NUL, then using -d '' will accomplish that: $ printf 'foo\0bar\n' | { read -d '' line; echo "$line"; read line; echo "$line"; } foo bar $