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

Re: more splitting travails





On Fri, Jan 12, 2024 at 2:57 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

% vvar=( ${"$(<testfile2)"} )


OK, that's interesting, you're using array assignment syntax ( vvar=( ... ) ) but you're only assigning a single value; after that assignment, $vvar[1] contains the entire contents of the file.  The blank lines aren't getting lost here because they're inside that one string, rather than being their own standalone values.

If you want to get the lines of the file into individual elements of an array, you can use the (f) expansion flag to split the file contents on newline. However, that will remove blank lines unless you also include the (@) flag to preserve them.  Which gives the recipe I mentioned in my last message:

    % vvar=("${(@f)"$(<testfile2)"}")

--
Mark J. Reed <markjreed@xxxxxxxxx>


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