[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

From: Dale R. Worley
Subject: Re: Unexpected history expanded in heredoc in $() or <()
Date: Fri, 29 May 2020 21:20:38 -0400

"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'
> !!
> ```
>       This doesn't work:
> ```
> cat <(cat <<'EOF'
> !!
> )
> ```
>       This doesn't work neither:
> ```
> echo "$(cat <<'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

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]