1 |
On Sat, 19 Dec 2015 21:17:26 +0100 |
2 |
Ulrich Mueller <ulm@g.o> wrote: |
3 |
|
4 |
> >>>>> On Sat, 19 Dec 2015, Michał Górny wrote: |
5 |
> |
6 |
> > read -d '' -r -a DOC_CONTENTS <<<"${DOC_CONTENTS}" |
7 |
> |
8 |
> > This performs word splitting into an array. Then you can do: |
9 |
> |
10 |
> > echo -e "${DOC_CONTENTS[*]}" | ... |
11 |
> |
12 |
> The first line fails for me: |
13 |
> |
14 |
> $ DOC_CONTENTS="test" |
15 |
> $ read -d '' -r -a DOC_CONTENTS <<<"${DOC_CONTENTS}" |
16 |
> $ echo $? |
17 |
> 1 |
18 |
> |
19 |
> (I guess it is encountering EOF on the temporary file created by the |
20 |
> string redirection, but how would one distinguish this from other |
21 |
> errors?) |
22 |
|
23 |
read's return code indicates whether if found a full line (with |
24 |
a newline). read can't really fail. |
25 |
|
26 |
> Besides, it is hard to understand what this code does, as compared to |
27 |
> the "set -f" solution. |
28 |
|
29 |
Many pieces of good code are harder to understand than cheap, ugly |
30 |
hacks. That's why those hacks are so common, and people meet them all |
31 |
the time and never learn good code. |
32 |
|
33 |
-- |
34 |
Best regards, |
35 |
Michał Górny |
36 |
<http://dev.gentoo.org/~mgorny/> |