642af4d
diff -up ksh-20120801/src/cmd/ksh93/sh/lex.c.heresub ksh-20120801/src/cmd/ksh93/sh/lex.c
642af4d
--- ksh-20120801/src/cmd/ksh93/sh/lex.c.heresub	2014-05-21 16:48:42.635700984 +0200
642af4d
+++ ksh-20120801/src/cmd/ksh93/sh/lex.c	2014-05-21 16:48:42.678700772 +0200
642af4d
@@ -1557,6 +1557,7 @@ static int comsub(register Lex_t *lp, in
642af4d
 {
642af4d
 	register int	n,c,count=1;
642af4d
 	register int	line=lp->sh->inlineno;
642af4d
+	struct ionod	*inheredoc = lp->heredoc;
642af4d
 	char *first,*cp=fcseek(0),word[5];
642af4d
 	int off, messages=0, assignok=lp->assignok, csub;
642af4d
 	struct lexstate	save;
642af4d
@@ -1683,7 +1684,7 @@ done:
642af4d
 	lp->lexd.dolparen--;
642af4d
 	lp->lex = save;
642af4d
 	lp->assignok = (endchar(lp)==RBRACT?assignok:0);
642af4d
-	if(lp->heredoc)
642af4d
+	if(lp->heredoc && !inheredoc)
642af4d
 		errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax5,lp->sh->inlineno,lp->heredoc->ioname);
642af4d
 	return(messages);
642af4d
 }
642af4d
diff -up ksh-20120801/src/cmd/ksh93/sh/macro.c.heresub ksh-20120801/src/cmd/ksh93/sh/macro.c
642af4d
--- ksh-20120801/src/cmd/ksh93/sh/macro.c.heresub	2014-05-21 16:48:42.650700910 +0200
642af4d
+++ ksh-20120801/src/cmd/ksh93/sh/macro.c	2014-05-21 16:48:42.678700772 +0200
642af4d
@@ -2085,7 +2085,7 @@ static void comsubst(Mac_t *mp,register
642af4d
 			}
642af4d
 			sfputc(stkp,c);
642af4d
 		}
642af4d
-		sfputc(stkp,' ');
642af4d
+		sfputc(stkp,'\n');
642af4d
 		c = stktell(stkp);
642af4d
 		str=stkfreeze(stkp,1);
642af4d
 		/* disable verbose and don't save in history file */