Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
mysterious newline
- X-seq: zsh-users 30764
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: mysterious newline
- Date: Thu, 19 Nov 2026 15:09:21 -0700
- Archived-at: <https://zsh.org/users/30764>
- List-id: <zsh-users.zsh.org>
This reads the lines in an array and if the
first words on each line are not identical a blank line in
inserted otherwise the lines are tight:
local prev="${(M)final[1]#*$' '}"
local final2=()
for ((ii=1; ii<=$#final; ii++)); do
ffile="${(M)final[ii]#*$' '}"
if [[ "$prev" == "$ffile" ]]; then
final2+=$final[ii]
else
final2+=" "
prev=$ffile
fi
done
... it works but I don't understand why. >final2+=" "<
creates a newline, which is what I want but it would seem to only
append a space, not a newline. Perhaps since final2 is an array,
zsh cleverly presumes that any '+=' must mean 'append to next
element'? I figger so but I'd better ask. IOW, if I wanted to
append a space to the end of the last element, I'd have to be
explicit about that, yes? It seems reasonable.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author