"ladyrick" <ladyr...@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

Reply via email to