heredoc seems to parse contents even with the quoted delimiter in shell prompt

1 view
Skip to first unread message

Hyunho Cho

unread,
Aug 16, 2020, 2:25:05 AM8/16/20
to bug-...@gnu.org
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release

####################################################################


if i use "test.sh" file for running shell script like this, there are
no error messages appear


bash$ cat test.sh
#!/bin/bash

cat << "EOF"
this is a test comment
$(info $(foo ${bar)))
EOF


bash$ ./test.sh # no error messages appear
this is a test comment
$(info $(foo ${bar)))

-----------------------------------------------------------------------------------------------------------

if i use the same script in shell prompt then strange error messages appear


bash$ cat << "EOF"
this is a test comment
$(info $(foo ${bar)))
EOF
bash: command substitution: line 798: unexpected EOF while looking for
matching `}'
bash: command substitution: line 799: syntax error: unexpected end of file
bash: command substitution: line 798: unexpected EOF while looking for
matching `}'
bash: command substitution: line 799: syntax error: unexpected end of file
this is a test comment
$(info $(foo ${bar)))

Chet Ramey

unread,
Aug 17, 2020, 9:23:46 AM8/17/20
to Hyunho Cho, bug-...@gnu.org, chet....@case.edu
On 8/16/20 1:34 AM, Hyunho Cho wrote:

>
> if i use the same script in shell prompt then strange error messages appear
>
>
> bash$ cat << "EOF"
> this is a test comment
> $(info $(foo ${bar)))
> EOF
> bash: command substitution: line 798: unexpected EOF while looking for
> matching `}'
> bash: command substitution: line 799: syntax error: unexpected end of file

Thanks for the report. The shell is trying to find the end of the command
to figure out how to store it in the history. When you're parsing a here-
document, you need to leave the newlines in the history instead of maybe
adding a semicolon. That code just needs to be more aware of when it can
not parse due to being in the body of a here-document.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ch...@case.edu http://tiswww.cwru.edu/~chet/

Reply all
Reply to author
Forward
0 new messages