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.
This commit is contained in:
parent
df1bc9de7c
commit
85307c9ed9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=222134
@ -1513,10 +1513,12 @@ checkend: {
|
|||||||
|
|
||||||
p = line;
|
p = line;
|
||||||
for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
|
for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
|
||||||
if (*p == '\n' && *q == '\0') {
|
if ((*p == '\0' || *p == '\n') && *q == '\0') {
|
||||||
c = PEOF;
|
c = PEOF;
|
||||||
plinno++;
|
if (*p == '\n') {
|
||||||
needprompt = doprompt;
|
plinno++;
|
||||||
|
needprompt = doprompt;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pushstring(line, strlen(line), NULL);
|
pushstring(line, strlen(line), NULL);
|
||||||
}
|
}
|
||||||
|
26
tools/regression/bin/sh/parser/heredoc11.0
Normal file
26
tools/regression/bin/sh/parser/heredoc11.0
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
failures=''
|
||||||
|
|
||||||
|
check() {
|
||||||
|
if eval "[ $* ]"; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
echo "Failed: $*"
|
||||||
|
failures=x$failures
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check '`cat <<EOF
|
||||||
|
foo
|
||||||
|
EOF` = foo'
|
||||||
|
|
||||||
|
check '"`cat <<EOF
|
||||||
|
foo
|
||||||
|
EOF`" = foo'
|
||||||
|
|
||||||
|
check '`eval "cat <<EOF
|
||||||
|
foo
|
||||||
|
EOF"` = foo'
|
||||||
|
|
||||||
|
test "x$failures" = x
|
Loading…
Reference in New Issue
Block a user