On Sat, 19 Dec 2015 21:17:26 +0100
Ulrich Mueller <[email protected]> wrote:

> >>>>> On Sat, 19 Dec 2015, Michał Górny wrote:  
> 
> >   read -d '' -r -a DOC_CONTENTS <<<"${DOC_CONTENTS}"  
> 
> > This performs word splitting into an array. Then you can do:  
> 
> >   echo -e "${DOC_CONTENTS[*]}" | ...  
> 
> The first line fails for me:
> 
> $ DOC_CONTENTS="test"
> $ read -d '' -r -a DOC_CONTENTS <<<"${DOC_CONTENTS}"
> $ echo $?
> 1
> 
> (I guess it is encountering EOF on the temporary file created by the
> string redirection, but how would one distinguish this from other
> errors?)

read's return code indicates whether if found a full line (with
a newline). read can't really fail.

> Besides, it is hard to understand what this code does, as compared to
> the "set -f" solution.

Many pieces of good code are harder to understand than cheap, ugly
hacks. That's why those hacks are so common, and people meet them all
the time and never learn good code.

-- 
Best regards,
Michał Górny
<http://dev.gentoo.org/~mgorny/>

Attachment: pgpOxiRpJgEbu.pgp
Description: OpenPGP digital signature

Reply via email to