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

Re: Apparent inconsistency in f/z expansion flags behavior



On Sun, Dec 18, 2016 at 5:02 PM, Pablo Lalloni <plalloni@xxxxxxxxx> wrote:

> Hello there!
>
> I'm seeing an unexpected (to me) difference in the behavior of these flags.
>
> Say you do something like:
>
> words=(${(z)$(</proc/meminfo)})
>
> Which set words with the array of all the words in the file and that's
> great.
>
> Then I try the f flag in place of z, expecting to get an array with the
> file's lines:
>
> lines=(${(f)$(</proc/meminfo)})
>
> But then I get an array with just one string containing all the lines
> concatenated (no NLs).
>
> So... Is this expected? What I need to do to get the array of lines?
>
> Note that if you split the last assignment in 2 steps, it works as
> expected:
>
> lines=$(</proc/meminfo)
> lines=(${(f)lines})
>
> Which is ok, but of course anybody would want to do it in one step, right?
>
> Cheers!
>

lines=("${(f)$(</proc/meminfo)}")

Should do what you want. You need the quotes. It took me a
while to get that into my own head.

Hope it helps,

Jim


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