Reproducing my comment [1] for the list:
> On Apr 4, 2024, at 5:57 PM, Richard Waite <invalid.nore...@gnu.org> wrote: > > Does variable expansion for here-documents occur in a subshell? Sometimes. When a command requires forking (roughly speaking), its redirections (not just here-documents) are processed after the fork as an optimization. For more details, including workarounds, see: - https://mywiki.wooledge.org/BashPitfalls#pf64 - https://www.vidarholen.net/contents/blog/?p=865 - https://lists.gnu.org/archive/html/help-bash/2024-02/msg00022.html > Checking the value of BASH_SUBSHELL seems to indicate no: This is not a context in which BASH_SUBSHELL is incremented. As per Chet [2]: > From: Chet Ramey <chet.ra...@case.edu> > Subject: Re: BASH_SUBSHELL is not incrementing when part of a pipeline > Date: August 8, 2023 at 10:06:48 AM EDT > To: Kamil Cukrowski Priv <kamilcukrow...@gmail.com>, bug-bash@gnu.org > Cc: chet.ra...@case.edu > Reply-To: chet.ra...@case.edu > > On 8/7/23 9:56 AM, Kamil Cukrowski Priv wrote: >> Hi, when BASH_SUBSHELL is part of a pipeline with just a simple command it >> does not increment. Consider the following: > > Yes. BASH_SUBSHELL increments for asynchronous commands (&), commands > explicitly in subshells, compound commands in pipelines, coprocesses, > process substitution, and command substitution. [1]: https://savannah.gnu.org/support/?111047#comment1 [2]: https://lists.gnu.org/archive/html/bug-bash/2023-08/msg00017.html -- vq