aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2011-05-20 16:03:36 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2011-05-20 16:03:36 +0000
commit85307c9ed9cfe02c2c19551f41495d97ef5b8ffb (patch)
treed36d4f985b72c55479a85a920658c3ee1fdf0b01 /bin
parentdf1bc9de7c37b49ca58c88cc20f6871b30c2b35b (diff)
downloadsrc-85307c9ed9cfe02c2c19551f41495d97ef5b8ffb.tar.gz
src-85307c9ed9cfe02c2c19551f41495d97ef5b8ffb.zip
sh: Allow terminating a heredoc with a terminator at EOF without a newline.
This is sometimes used with eval or old-style command substitution, and most shells other than ash derivatives allow it. It can also be used with scripts that violate POSIX's requirement on the application that they end in a newline (scripts must be text files except that line length is unlimited). Example: v=`cat <<EOF foo EOF` echo $v This commit does not add support for the similar construct with new-style command substitution, like v=$(cat <<EOF foo EOF) This continues to require a newline after the terminator.
Notes
Notes: svn path=/head/; revision=222134
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index cc1860df22fd..192769b076c4 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1513,10 +1513,12 @@ checkend: {
p = line;
for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
- if (*p == '\n' && *q == '\0') {
+ if ((*p == '\0' || *p == '\n') && *q == '\0') {
c = PEOF;
- plinno++;
- needprompt = doprompt;
+ if (*p == '\n') {
+ plinno++;
+ needprompt = doprompt;
+ }
} else {
pushstring(line, strlen(line), NULL);
}