1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
BASH PATCH REPORT
=================
Bash-Release: 5.2
Patch-ID: bash52-003
Bug-Reported-by: D630 <d630@posteo.net>
Bug-Reference-ID: <cf8523d58ac75b9ffba9519faa175618@posteo.de>
Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2022-10/msg00092.html
Bug-Description:
Command substitutions need to preserve newlines instead of replacing them
with semicolons, especially in the presence of multiple here-documents.
--- 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_ */
--- 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, fl
cmdcopy->redirects = func_redirects;
}
else
- newline ("}");
+ { /* { */
+ newline ("}");
+ was_heredoc = 0;
+ }
result = the_printed_command;
|