On Mon, Nov 28, 2011 at 11:00:50PM -0500, Matthew Story wrote:
> bash-4.2$ printf 'foo\0bar\0' | while read -d '' line; do echo "$line"; done
> foo
> bar
> 
> I find this behavior incongruent with what I expect from setting things like
> IFS to empty string (e.g. delim is every character), but it seems like it is
> already in use.

It's extraordinarily useful.  It allows you to do things like this:

while IFS= read -rd '' file; do ...; done < <(find . -type f -print0)

Setting IFS to the empty string actually means that no word splitting or
trimming will be performed at all.  It does *not* mean that word splitting
happens on every character.

> I have a patch to make terminate input line after every character for -d '',
> and after null-byte on -d '\0', if you are interested in that functionality,
> I'll send that patch for your consideration as well.

There are many bash scripts in use already that rely on read -d '' to
work the way it does.  Switching the behavior of -d '' and introducing
-d '\0' in its place would require rewriting all of those scripts.

The final decision is Chet's, but losing the ability to read a
NUL-delimited stream would be a huge problem for me.  Neither POSIX sh
nor ksh has the ability to handle NUL-delimited input, as far as I have
been able to determine.  I don't know zsh, so maybe it does, or maybe not.

Reply via email to