Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16321

Re: Unexpected history expanded in heredoc in $() or <()

From worley@alum.mit.edu (Dale R. Worley)
Newsgroups gnu.bash.bug
Subject Re: Unexpected history expanded in heredoc in $() or <()
Date 2020-05-29 21:20 -0400
Message-ID <mailman.680.1590801655.2541.bug-bash@gnu.org> (permalink)
References <tencent_487241FE2E73B9237E6574D052A92DD1DE0A@qq.com> <87imgegqvt.fsf@hobgoblin.ariadne.com>

Show all headers | View raw


"ladyrick" <ladyrick@qq.com> writes:
> Description:
> 	A heredoc starts with "cat <<'EOF'" is expected to not expand
> 	anything just like in a single quote string. But when this
> 	heredoc is in a $() or <(), history is expanded.
>
>
> Repeat-By:
> 	This works:
> ```
> cat <<'EOF'
> !!
> EOF
> ```
> 	This doesn't work:
> ```
> cat <(cat <<'EOF'
> !!
> EOF
> )
> ```
> 	This doesn't work neither:
> ```
> echo "$(cat <<'EOF'
> !!
> EOF
> )"
> ```

It's a messy case; what's really happening the the last two examples is
that the entire thing is read and processed as one "line", because bash
reads all of the command or process substitution as a unit.  Then it
performs history expansion, and then it interprets the line.  So the
history expansion is done before bash even recognizes that there is a
here-doc.

In the first example, bash reads "cat <<'EOF'" and starts processing
it.  At that point, it recognizes that it must read a here-doc and does
so.

Dale

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Unexpected history expanded in heredoc in $() or <() worley@alum.mit.edu (Dale R. Worley) - 2020-05-29 21:20 -0400

csiph-web