about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2024-03-17 14:28:28 -0700
committerBart Schaefer <schaefer@zsh.org>2024-03-17 14:28:28 -0700
commit25182cc2e69ab1cfeeb3f0faa1d28d774393043b (patch)
treeaef59e3f6da6763142c40cc6139c9b1edac21175 /Src
parent45b0a838aa6e05131523dee291c561cf86f04771 (diff)
downloadzsh-25182cc2e69ab1cfeeb3f0faa1d28d774393043b.tar.gz
zsh-25182cc2e69ab1cfeeb3f0faa1d28d774393043b.tar.xz
zsh-25182cc2e69ab1cfeeb3f0faa1d28d774393043b.zip
52759: ${ ... } trims one trailing newline; "${ ... }" preserves that newline.
Diffstat (limited to 'Src')
-rw-r--r--Src/subst.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Src/subst.c b/Src/subst.c
index 49f7336bb..9d20a2d0e 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1900,6 +1900,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 	/* The command string to be run by ${|...;} */
 	char *cmdarg = NULL;
 	size_t slen = 0;
+	int trim = (!EMULATION(EMULATE_ZSH)) ? 2 : !qt;
 	inbrace = 1;
 	s++;
 
@@ -2005,10 +2006,13 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		int onoerrs = noerrs, rplylen;
 		noerrs = 2;
 		rplylen = zstuff(&cmdarg, rplytmp);
-		if (! EMULATION(EMULATE_ZSH)) {
+		if (trim) {
 		    /* bash and ksh strip trailing newlines here */
-		    while (rplylen > 0 && cmdarg[rplylen-1] == '\n')
+		    while (rplylen > 0 && cmdarg[rplylen-1] == '\n') {
 			rplylen--;
+			if (trim == 1)
+			    break;
+		    }
 		    cmdarg[rplylen] = 0;
 		}
 		noerrs = onoerrs;