Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH?] Nofork and removing newlines
On Wed, Mar 6, 2024 at 11:10 PM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> For ${=${ foo }} that depends on whether $IFS contains a
> (non-doubled) newline or not.
True, but I think not really relevant, because nobody is (I hope)
going to globally set a strange IFS in their dotfiles and still expect
any normal behavior.
> For (f), see also:
>
> $ printf '<%s>\n' "${(f@)${ print -l 'a b' '' 'c d' }}"
> <a b>
> <>
> <c d>
> <>
That's because of the historic behavior of the (s::) flag where (f) is
(ps:\n:). But as was pointed out elsewhere if you're not invoking an
external command you can control this from inside the substitution:
% printf '<%s>\n' "${(f@)${ print -nl 'a b' '' 'c d' }}"
<a b>
<>
<c d>
%
Which leans a little in the direction of never trimming rather than of
choosing how many to trim.
It does however reveal a drawback in the quoting proposal, in that
when nesting ${ ... } inside another quoted expansion there would be
no way to disable newline retention.
> We'd need to have a way to treat the separator as *delimiter*
That would be a useful choice for (T) or some other new flag -- as in,
do NOT "trim" the separator when splitting -- but I don't see how it
helps decide whether to trim trailing newline(s) from ${ cmd } in the
first place, because in the delimiter case you'd want to keep them?
Just for grins ...
% : ${|reply|
typeset -ga reply
local -i i=1 MBEGIN MEND
local -n MATCH='reply[i]'
local pat=$'[^\n]#\n'
: ${(*S)"${ print -l 'a b' '' 'c d' }"//(#m)($~pat)/$((i++))}
}
% typeset -p reply
typeset -a reply=( $'a b\n' $'\n' $'c d\n' )
Messages sorted by:
Reverse Date,
Date,
Thread,
Author