Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: worley@alum.mit.edu (Dale R. Worley) Newsgroups: gnu.bash.bug Subject: Re: Unexpected history expanded in heredoc in $() or <() Date: Fri, 29 May 2020 21:20:38 -0400 Lines: 42 Approved: bug-bash@gnu.org Message-ID: References: (ladyrick@qq.com) <87imgegqvt.fsf@hobgoblin.ariadne.com> NNTP-Posting-Host: lists.gnu.org X-Trace: usenet.stanford.edu 1590801656 32694 209.51.188.17 (30 May 2020 01:20:56 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org, bash@packages.debian.org To: "ladyrick" Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20180828_2048; t=1590801643; bh=Q9rmUsRNjUePEK6G7TzkPZdJGTtv3mN0t5uTkscouvc=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID; b=MTzJByo19TNEoBFmLWcseIB9VZ2SA/CJXbbljjvaj7MWZwmKeAc/LQttA65nC5j7x cH/tocNoCwTMMRBoe8XBqgCQ3Nqf6w0woxxjYJ9UTx37kD4nxumAKUyXv7N4bkFwM4 rJZcCKiuKteQtRvOqr1I2AGSe5aK/CdBjrW17qj8cX0q93twJKlfCC6HRX+Fg5Xu47 +uFp4lcUHSPIvB9FogRawdjhPK28YIA0dBI5i83RX/TYU1UxC2vNCIJwXm46ZzGGK9 hg01agaNZSzi6HCNHWUH7ixAguj1n5EQ3Wx2Y10tbp63pGiMXksaJwoBPsdcXEQTMF X1DmPKo4h/R6g== X-Xfinity-VMeta: sc=0.00;st=legit X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f In-Reply-To: (ladyrick@qq.com) Received-SPF: permerror client-ip=2001:558:fe21:29:69:252:207:44; envelope-from=worley@alum.mit.edu; helo=resqmta-ch2-12v.sys.comcast.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/29 21:20:43 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, T_SPF_PERMERROR=0.01, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <87imgegqvt.fsf@hobgoblin.ariadne.com> Xref: csiph.com gnu.bash.bug:16321 "ladyrick" 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