[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Understanding read -r
From: |
Dan Douglas |
Subject: |
Re: [Help-bash] Understanding read -r |
Date: |
Thu, 04 Oct 2012 17:58:11 -0500 |
User-agent: |
KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; ) |
On Thursday, September 27, 2012 11:03:54 AM Bob Proulx wrote:
> Peng Yu wrote:
> > The following example shows that "\" at the line end means line
> > continuation. Is this wrong? Or I misunderstand the document?
>
> You forgot to quote the EOF part. See the stackoverflow reference.
> Therefore the shell interpreted the string contents before 'read'
> processing.
>
> > read -r -d '' VAR <<EOF
>
> Add quotes there.
>
> read -r -d '' VAR <<'EOF'
>
> Again, this has to do with the here-document part and not the 'read' part.
>
> Bob
This also suppresses the expansions of course. Not sure if you want that.
{ var=$(</dev/stdin); } <<EOF
blah
$foo $bar\
more text
EOF
Now both line continuations and expansions are done as you probably want them,
rather than letting read mangle things without -r.
As an aside, mksh has an interesting syntax to assign a heredoc result directly
to a variable:
# mksh
var=<<EOF
...
EOF
This is optimized to happen in memory with no temporary file.
--
Dan Douglas