c58d3ff
diff --git a/patchlevel.h b/patchlevel.h
c58d3ff
--- a/patchlevel.h
c58d3ff
+++ b/patchlevel.h
c58d3ff
@@ -25,6 +25,6 @@
c58d3ff
    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
c58d3ff
    looks for to find the patch level (for the sccs version string). */
c58d3ff
 
c58d3ff
-#define PATCHLEVEL 2
c58d3ff
+#define PATCHLEVEL 3
c58d3ff
 
c58d3ff
 #endif /* _PATCHLEVEL_H_ */
c58d3ff
diff --git a/print_cmd.c b/print_cmd.c
c58d3ff
--- a/print_cmd.c
c58d3ff
+++ b/print_cmd.c
c58d3ff
@@ -297,10 +297,12 @@ make_command_string_internal (command)
c58d3ff
 	    case '\n':				/* special case this */
c58d3ff
 	      {
c58d3ff
 		char c = command->value.Connection->connector;
c58d3ff
+		int was_newline;
c58d3ff
 
c58d3ff
 		s[0] = printing_comsub ? c : ';';
c58d3ff
 		s[1] = '\0';
c58d3ff
 
c58d3ff
+		was_newline = deferred_heredocs == 0 && was_heredoc == 0 && c == '\n';
c58d3ff
 		if (deferred_heredocs == 0)
c58d3ff
 		  {
c58d3ff
 		    if (was_heredoc == 0)
c58d3ff
@@ -314,6 +316,8 @@ make_command_string_internal (command)
c58d3ff
 
c58d3ff
 		if (inside_function_def)
c58d3ff
 		  cprintf ("\n");
c58d3ff
+		else if (printing_comsub && c == '\n' && was_newline == 0)
c58d3ff
+		  cprintf ("\n");	/* preserve newlines in comsubs but don't double them */
c58d3ff
 		else
c58d3ff
 		  {
c58d3ff
 		    if (c == ';')
c58d3ff
@@ -1365,7 +1369,11 @@ print_function_def (func)
c58d3ff
       cmdcopy->redirects = func_redirects;
c58d3ff
     }
c58d3ff
   else
c58d3ff
-    newline ("}");
c58d3ff
+    {
c58d3ff
+      /* { */
c58d3ff
+      newline ("}");
c58d3ff
+      was_heredoc = 0;		/* not printing any here-documents now */
c58d3ff
+    }
c58d3ff
 
c58d3ff
   dispose_command (cmdcopy);
c58d3ff
 }
c58d3ff
@@ -1442,7 +1450,10 @@ named_function_string (name, command, flags)
c58d3ff
       cmdcopy->redirects = func_redirects;
c58d3ff
     }
c58d3ff
   else
c58d3ff
-    newline ("}");
c58d3ff
+    {	/* { */
c58d3ff
+      newline ("}");
c58d3ff
+      was_heredoc = 0;
c58d3ff
+    }
c58d3ff
 
c58d3ff
   result = the_printed_command;