Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Fwd: more splitting travails




On 2024-01-12 12:51, Bart Schaefer wrote:
On Fri, Jan 12, 2024 at 12:32 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
     % vvar=("${(@f)"$(<testfile2)"}")

... and that's not as Byzantine as it looks: " (@f) : read: "include blank lines, and split on newlines (including empty lines) "   ... Yes?
Close.  It's the inner double quotes around $(<...) that preserve the
exact contents of the file.**
Yes
(f) means split on newlines
Yup
and (@)
means "this is an array, don't join it into a string".
There's a mistake: I thought the @ was what meant 'all lines'.
   Then the
outermost set of double quotes means "include empty array elements"
(which, because of (f), is empty lines in this case).

Nuts, if the innermost quotes say 'exact contents' then that seems redundant.

And I thought the outermost parenthesis said 'this is an array', not the '@'

** Except that $(...) trims off TRAILING newlines, so if the last
line(s) of the file are blank they'll vanish.

Easy when you know how.






Messages sorted by: Reverse Date, Date, Thread, Author