[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64)
From: |
Greg Wooledge |
Subject: |
Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64) |
Date: |
Tue, 29 Nov 2011 08:29:53 -0500 |
User-agent: |
Mutt/1.4.2.3i |
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.
- read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/23
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Greg Wooledge, 2011/11/23
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Chet Ramey, 2011/11/23
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/23
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Chet Ramey, 2011/11/23
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/23
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Chet Ramey, 2011/11/24
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/28
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64),
Greg Wooledge <=
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Chet Ramey, 2011/11/29
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/29
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/29
- Re: read fails on null-byte: v4.1.7 FreeBSD 8.0 (amd64), Matthew Story, 2011/11/23