From: Stephane Chazelas <stephane@chazelas.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH?] Nofork and removing newlines
Date: Tue, 5 Mar 2024 06:56:06 +0000 [thread overview]
Message-ID: <20240305065606.ccr2ieheahslcpye@chazelas.org> (raw)
In-Reply-To: <CAH+w=7aFJH-5GAu6puszGKvjqN-w0sPCi6v-vGPauDHVujDnag@mail.gmail.com>
2024-03-04 21:52:02 -0800, Bart Schaefer:
[...]
> mytt($(command)) removes trailing newlines from the output of mytt(command)
> - when substituting, whereas mytt(${ command }) and its variants do not.
> - The latter is consistent with mytt(${|...}) from mksh but differs from
> - bash and ksh, so in emulation modes, newlines are stripped from command
> - output (not from tt(REPLY) assignments).
> + when substituting, as does mytt(${ command }) when not quoted. Placing
> + double quotes around mytt("${ command }"), or using either mytt(${|...})
> + format, retains newlines. The latter is consistent with mytt(${|...})
> + from mksh, but mytt("${ command }") differs from bash and ksh, so in
> + emulation modes, newlines stripped even from quoted command output.
^^^ typo missing "are".
To me ${ cmd; } being the non-forking version of $(...) should
behave like $(...) in that regard.
IMO, it's a bug in Bourne-like shells (and some others) that
$(...) removes *all* trailing newline characters, but removing
*one* is usually desired.
As in:
basename=$(basename -- "$file")
should remove the newline added by basename, but not the newline
characters that are found at the end of $file.
In any case, I agree ${|cmd} should expand to the value of
$REPLY as-is and trimming newlines there would not make sense.
IIRC I already mentioned it here but maybe having a:
ZSH_CMDSUBST_TRIM=<extendedglobpattern> (defaulting to $'\n##'
for backward compatibility) could address the general issue with
cmdsubst trimming too many newlines (for both $(...) and ${...;}).
One would change it to
ZSH_CMDSUBST_TRIM=$'\n' to get a saner default, or
ZSH_CMDSUBST_TRIM= to not remove anything or
ZSH_CMDSUBST_TRIM=$'(\r|)\n' or
ZSH_CMDSUBST_TRIM='[[:space:]]##' to handle MSDOS line
delimiters or remove any whitespace.
>
> When not enclosed in double quotes, the expansion of mytt($(command)) is
> split on tt(IFS) into an array of words.
unless called in non-list contexts such as in scalar variable
assignment or [[ $var ]] or case $var in...
See also:
$ ./Src/zsh -c 'a=( "${(s[:])${ getconf PATH }}" ); typeset -p a'
typeset -a a=( /bin $'/usr/bin\n' )
--
Stephane
next prev parent reply other threads:[~2024-03-05 6:56 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 5:52 Bart Schaefer
2024-03-05 6:56 ` Stephane Chazelas [this message]
2024-03-05 22:48 ` Bart Schaefer
2024-03-06 17:57 ` Stephane Chazelas
2024-03-06 19:45 ` Bart Schaefer
2024-03-06 22:22 ` Mikael Magnusson
2024-03-06 22:42 ` Bart Schaefer
2024-03-07 4:53 ` Bart Schaefer
2024-03-07 7:02 ` Lawrence Velázquez
2024-03-07 8:09 ` ${<file} (Was: [PATCH?] Nofork and removing newlines) Stephane Chazelas
2024-03-08 1:29 ` [PATCH?] Nofork and removing newlines Bart Schaefer
2024-03-08 22:15 ` Oliver Kiddle
2024-03-08 23:28 ` Bart Schaefer
2024-03-09 20:43 ` Oliver Kiddle
2024-03-10 6:11 ` Bart Schaefer
2024-03-12 17:54 ` Bart Schaefer
2024-03-12 23:19 ` Oliver Kiddle
2024-03-13 4:13 ` Bart Schaefer
2024-03-14 22:15 ` Oliver Kiddle
2024-03-15 8:42 ` Stephane Chazelas
2024-03-27 1:16 ` Bart Schaefer
2024-03-27 7:05 ` Bart Schaefer
2024-03-07 7:10 ` Stephane Chazelas
2024-03-08 0:37 ` Bart Schaefer
2024-03-07 6:52 ` Lawrence Velázquez
2024-03-07 8:26 ` Mikael Magnusson
2024-03-07 19:02 ` Bart Schaefer
2024-04-02 6:45 ` Lawrence Velázquez
2024-03-06 19:43 ` Stephane Chazelas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240305065606.ccr2ieheahslcpye@chazelas.org \
--to=stephane@chazelas.org \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).