summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2022-11-07 11:39:47 -0500
committerChet Ramey <chet.ramey@case.edu>2022-11-07 11:39:47 -0500
commit3039110d0884ab0c52e46d369f0c55f79b1f8288 (patch)
treec506181738326dbec413309a89c2f3e97ba78682
parenta99d905216cc0aac5de0c3050f4afc54e21c6bc5 (diff)
downloadbash-3039110d0884ab0c52e46d369f0c55f79b1f8288.tar.gz
Bash-5.2 patch 3: preserve newlines while parsing command substitutions
-rw-r--r--patchlevel.h2
-rw-r--r--print_cmd.c15
2 files changed, 14 insertions, 3 deletions
diff --git a/patchlevel.h b/patchlevel.h
index d465c244..40f26f7b 100644
--- a/patchlevel.h
+++ b/patchlevel.h
@@ -25,6 +25,6 @@
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
looks for to find the patch level (for the sccs version string). */
-#define PATCHLEVEL 2
+#define PATCHLEVEL 3
#endif /* _PATCHLEVEL_H_ */
diff --git a/print_cmd.c b/print_cmd.c
index eef9bb6a..b8154947 100644
--- a/print_cmd.c
+++ b/print_cmd.c
@@ -297,10 +297,12 @@ make_command_string_internal (command)
case '\n': /* special case this */
{
char c = command->value.Connection->connector;
+ int was_newline;
s[0] = printing_comsub ? c : ';';
s[1] = '\0';
+ was_newline = deferred_heredocs == 0 && was_heredoc == 0 && c == '\n';
if (deferred_heredocs == 0)
{
if (was_heredoc == 0)
@@ -314,6 +316,8 @@ make_command_string_internal (command)
if (inside_function_def)
cprintf ("\n");
+ else if (printing_comsub && c == '\n' && was_newline == 0)
+ cprintf ("\n"); /* preserve newlines in comsubs but don't double them */
else
{
if (c == ';')
@@ -1365,7 +1369,11 @@ print_function_def (func)
cmdcopy->redirects = func_redirects;
}
else
- newline ("}");
+ {
+ /* { */
+ newline ("}");
+ was_heredoc = 0; /* not printing any here-documents now */
+ }
dispose_command (cmdcopy);
}
@@ -1442,7 +1450,10 @@ named_function_string (name, command, flags)
cmdcopy->redirects = func_redirects;
}
else
- newline ("}");
+ { /* { */
+ newline ("}");
+ was_heredoc = 0;
+ }
result = the_printed_command;