> > > If you want to handle a stream of NUL-delimited strings in bash, the > best approach is to use read -d '', thus: > > imadev:~$ printf '%s\0' one two three | while read -r -d '' s; do echo > "<$s>"; done > <one> > <two> > <three> > > read -d '' means "stop at NUL, instead of stopping at newline". >
Thanks for your reply. I was aware of your solution, but in my situation the '\0' problem makes things more complicated: I have a program which outputs groups of filenames. Each group is separated by a newline, and within each group, each name is separated by '\0'. I want to pipe each group to xargs -0. But because of this '\0' implementation detail (I did not find it is documented). the following solution (working in zsh) don't work in bash (and I couldn't find a non-convoluted solution in bash) : myprog | while read group; do echo $group | tr -d '\n' | xargs -0 ls -1; done If I use <while read -r -d '' ...>, I don't know how to break on each line... A solution with mapfile would be even better, but mapfile has the same problem as read in this regard.