Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH?] Nofork and removing newlines
- X-seq: zsh-workers 52706
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Mikael Magnusson <mikachu@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH?] Nofork and removing newlines
- Date: Thu, 7 Mar 2024 07:10:16 +0000
- Archived-at: <https://zsh.org/workers/52706>
- In-reply-to: <CAH+w=7Yq7e7JOiN51=vQjUvS+Yi6xY0VAJUGjoraeBKKazAnkw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Mikael Magnusson <mikachu@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <CAH+w=7aFJH-5GAu6puszGKvjqN-w0sPCi6v-vGPauDHVujDnag@mail.gmail.com> <20240305065606.ccr2ieheahslcpye@chazelas.org> <CAH+w=7Yb6_eULBq6Ez6pEhtUXOqErr+aDL2BDi7zyxr8QpsTiw@mail.gmail.com> <20240306175711.t3uz2sery3b6tbjw@chazelas.org> <CAH+w=7a5K8ioO+mP8RXvtmawHJFfFw1jOWE49GmZdAOVaTPjUQ@mail.gmail.com> <CAHYJk3Tmh0xVQodHuXycDDv21_xgkhq5hvGZgPrZbLUYox2bGA@mail.gmail.com> <CAH+w=7Yq7e7JOiN51=vQjUvS+Yi6xY0VAJUGjoraeBKKazAnkw@mail.gmail.com>
2024-03-06 20:53:28 -0800, Bart Schaefer:
[...]
> > "${ foo}" and ${ foo} having the same wordsplitting behavior but only
> > differing in stripping newlines feels a bit magical and weird.
>
> One question (and sort of the point) is whether anyone would really
> notice. If you put it in quotes you're expecting a literal result,
> and if you (for example) assign it unquoted to a scalar you're
> expecting it to "just work" the way assigning $(foo) would. It's a
> bit unusual but it seems to preserve the principle of least surprise,
> and it uses the least amount of extra syntax.
>
> On the other hand I'm not highly invested in this. In the absence of
> this (no)quoting behavior, I've found I nearly always want ${=${ foo
> }} or ${(f)${ foo }}, each of which gives exactly the same result with
> or without trimming.
[...]
For ${=${ foo }} that depends on whether $IFS contains a
(non-doubled) newline or not.
Without trimming:
$ IFS=:
$ printf '<%s>\n' ${=${ getconf PATH }}
</bin>
</usr/bin
>
$ IFS=$'\n\n'
$ printf '<%s>\n' ${=${ seq 3 }}
<1>
<2>
<3>
<>
For (f), see also:
$ printf '<%s>\n' "${(f@)${ print -l 'a b' '' 'c d' }}"
<a b>
<>
<c d>
<>
Like with IFS=$'\n\n', those are typically the cases where you
do want to preserve empty lines.
In both cases, trimming one (and only one) newline character
would lead to a better behaviour. One exception would be in:
lines=( "${(f@)${ print -l '' }}" )
Where you'd get no line instead of one empty line. Though at the moment, you get:
$ lines=( "${(f@)${ print -l '' }}" )
$ typeset -p lines
typeset -a lines=( '' '' )
(2 empty lines) which is not better.
We'd need to have a way to treat the separator as *delimiter*
instead (as POSIX requires for IFS splitting despite the S in
IFS; both "delimiting" and "separating" have their use).
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author