Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: <<<: Document newline behavior and fix optimization
- X-seq: zsh-workers 49813
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: <<<: Document newline behavior and fix optimization
- Date: Tue, 8 Mar 2022 19:58:32 +0100
- Archived-at: <https://zsh.org/workers/49813>
- List-id: <zsh-workers.zsh.org>
The =(<<<foo) optimization forgot to add a newline, but =(cat<<<foo)
always did, make the behavior consistent, and document it.
---
This optimization was added in 2005 in workers/21758 (ad2bd42c858) and
has no motivation for excluding the newline, so I assume it's just a
minor mistake.
---
Doc/Zsh/redirect.yo | 3 ++-
README | 5 +++++
Src/exec.c | 4 +++-
Test/A04redirect.ztst | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo
index 2b48974b40..fd40ab5a4b 100644
--- a/Doc/Zsh/redirect.yo
+++ b/Doc/Zsh/redirect.yo
@@ -86,7 +86,8 @@ item(tt(<<<) var(word))(
Perform shell expansion on var(word) and pass the result
to standard input. This is known as a em(here-string).
Compare the use of var(word) in here-documents above, where var(word)
-does not undergo shell expansion.
+does not undergo shell expansion. The result will have a trailing newline
+after it.
)
xitem(tt(<&) var(number))
item(tt(>&) var(number))(
diff --git a/README b/README
index 353667289e..153f02b25b 100644
--- a/README
+++ b/README
@@ -33,6 +33,11 @@ details, see the documentation.
Incompatibilities since 5.8
---------------------------
+The optimization for the =(<<<foo) construct with no command, which
+creates a temporary file with contents "foo", now adds a newline byte
+after "foo" for consistency with the behaviour of the <<< redirection
+everywhere else.
+
PROMPT_SUBST expansion is no longer performed on arguments to prompt-
expansion sequences such as %F.
diff --git a/Src/exec.c b/Src/exec.c
index f67074846f..70cbfc97fd 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4836,8 +4836,10 @@ getoutputfile(char *cmd, char **eptr)
singsub(&s);
if (errflag)
s = NULL;
- else
+ else {
untokenize(s);
+ s = dyncat(s, "\n");
+ }
}
if (!s) /* Unclear why we need to do this before open() */
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index 993138e7dc..17f6dfa29a 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -440,7 +440,7 @@
# This tests the here-string to filename optimisation; we can't
# test that it's actually being optimised, but we can test that it
# still works.
- cat =(<<<$'This string has been replaced\nby a file containing it.\n')
+ cat =(<<<$'This string has been replaced\nby a file containing it.')
0:Optimised here-string to filename
>This string has been replaced
>by a file containing it.
--
2.15.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author