If there are multiple commands in a row that each require printing the
connector prior to the heredoc body, the connector ends up in the wrong
place for commands after the first:

fun() {
cat <<EOF &&
EOF
cat <<EOF &&
EOF
cat <<EOF
EOF
}
declare -f fun

fun ()
{
    cat <<EOF &&
EOF
 cat <<EOF
EOF
 && cat <<EOF
EOF

}

This fix worked for every test case I could think of but I can't say
I'm groking all the printing logic yet.
---
 print_cmd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/print_cmd.c b/print_cmd.c
index d7c5bbf9..a38c1b3a 100644
--- a/print_cmd.c
+++ b/print_cmd.c
@@ -154,6 +154,7 @@ make_command_string (COMMAND *command)
   command_string_index = was_heredoc = 0;
   deferred_heredocs = 0;
   make_command_string_internal (command);
+  PRINT_DEFERRED_HEREDOCS ("");
   return (the_printed_command);
 }

@@ -327,7 +328,8 @@ make_command_string_internal (COMMAND *command)
      }

    make_command_string_internal (command->value.Connection->second);
-   PRINT_DEFERRED_HEREDOCS ("");
+   if (was_heredoc)
+     PRINT_DEFERRED_HEREDOCS ("");
    printing_connection--;
    break;

-- 
2.41.0

Reply via email to