Discussion:
[Help-bash] Is read -d '' officially supported?
Ulrich Mueller
2016-10-30 11:57:46 UTC
Permalink
While discussing some updates for the Gentoo developer manual, the
question arose if a construct like the following is officially
supported Bash behaviour:

while IFS="" read -d '' -r f ; do
echo "Calling down holy vengance upon $f"
done < <(find "${S}" -type f -print0)

Apparently "read -d ''" or "read -d $'\0'" have some real-world use:
http://unix.stackexchange.com/questions/61029/why-is-0-the-same-as
http://stackoverflow.com/questions/8677546/bash-for-in-looping-on-null-delimited-string-variable

However, according to the documentation:

'-d DELIM'
The first character of DELIM is used to terminate the input
line, rather than newline.

An empty string has no first character, so strictly speaking -d ''
would be undefined behaviour?
Eduardo Bustamante
2016-10-30 16:43:35 UTC
Permalink
It is not documented behavior, but it is certainly relied upon by many
to process NUL delimited input streams:
http://mywiki.wooledge.org/BashFAQ/001

So I wouldn't call it undefined behavior.
Chet Ramey
2016-10-30 17:24:40 UTC
Permalink
Post by Eduardo Bustamante
It is not documented behavior, but it is certainly relied upon by many
http://mywiki.wooledge.org/BashFAQ/001
So I wouldn't call it undefined behavior.
https://lists.gnu.org/archive/html/bug-bash/2016-01/msg00121.html
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://cnswww.cns.cwru.edu/~chet/
Ulrich Mueller
2016-10-30 18:47:36 UTC
Permalink
Post by Chet Ramey
Post by Eduardo Bustamante
It is not documented behavior, but it is certainly relied upon by many
http://mywiki.wooledge.org/BashFAQ/001
So I wouldn't call it undefined behavior.
https://lists.gnu.org/archive/html/bug-bash/2016-01/msg00121.html
I had hoped for a more straight forward answer than "You do have to
understand how C strings work and how they are used when passing
arguments to commands for it to make sense." :)

Can we rely on -d '' as supported/documented behaviour?
Chet Ramey
2016-10-30 20:20:14 UTC
Permalink
Post by Ulrich Mueller
Post by Chet Ramey
Post by Eduardo Bustamante
It is not documented behavior, but it is certainly relied upon by many
http://mywiki.wooledge.org/BashFAQ/001
So I wouldn't call it undefined behavior.
https://lists.gnu.org/archive/html/bug-bash/2016-01/msg00121.html
I had hoped for a more straight forward answer than "You do have to
understand how C strings work and how they are used when passing
arguments to commands for it to make sense." :)
Maybe you should look at the "there's no reason it should not just work"
and "it's not a special case that needs to be documented as such", then.
Post by Ulrich Mueller
Can we rely on -d '' as supported/documented behaviour?
I have no plans to change it.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://cnswww.cns.cwru.edu/~chet/
Ulrich Mueller
2016-10-30 21:58:36 UTC
Permalink
Post by Chet Ramey
Post by Ulrich Mueller
Can we rely on -d '' as supported/documented behaviour?
I have no plans to change it.
That still isn't an answer to my question.
Chet Ramey
2016-10-30 23:32:16 UTC
Permalink
Post by Ulrich Mueller
Post by Chet Ramey
Post by Ulrich Mueller
Can we rely on -d '' as supported/documented behaviour?
I have no plans to change it.
That still isn't an answer to my question.
Jesus. Then how about "yes, and if it changes report it as a bug." Can
we put this to rest now?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://cnswww.cns.cwru.edu/~chet/
Ulrich Mueller
2016-10-31 05:57:02 UTC
Permalink
Post by Chet Ramey
Post by Ulrich Mueller
Post by Chet Ramey
Post by Ulrich Mueller
Can we rely on -d '' as supported/documented behaviour?
I have no plans to change it.
That still isn't an answer to my question.
Jesus. Then how about "yes, and if it changes report it as a bug."
Can we put this to rest now?
Yes. Thank you. :-)

Loading...