Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Apparent inconsistency in f/z expansion flags behavior
- X-seq: zsh-users 22240
- From: Pablo Lalloni <plalloni@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Apparent inconsistency in f/z expansion flags behavior
- Date: Mon, 19 Dec 2016 12:02:00 -0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=E6IvPcFYHy9PriQqmpj3tGoIlsiuI7J3jyPBp5FreHI=; b=q7jlBYur+t9PVIPdRcF3f9zmizdit+JqjVDB2+Z2X+YubxbV6rZwxDdnvxs3sLyt8W NrgT7UAaQESRqdgINxiQTkwdRF2zWIuKBrYugrq8pCy2BaPXoZri9OhZiSG9I8sc700m ZUHfEhrffiZML5+Nn2NhZN+ONag+mU1w5x3N5TiVzYGesXsm+UVfI3edw7n+LpkeNOpL xGngtT3vYLJXx6Q5tQeAm9yOL0z8nRnRD/VnyMIIEQnzTLDIK7ket+7c7XbVFae2xWaO R6E06x8f9o+0Vh3/1W3f2WC8ujNS54GzK0h58APHpAAKTK8UzUgBK9+0IhSoEq0f3Ir+ irKA==
- In-reply-to: <161218180807.ZM5238@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAAiKvi0Ge4-9016srG4K5-3-VnwCXN5FcKtsjGtE6GjG8ZwGsA@mail.gmail.com> <161218180807.ZM5238@torch.brasslantern.com>
Thanks for your responses guys.
Both variations works as you said.
Better yet, I understand why.
Cheers!
On Sun, Dec 18, 2016 at 11:08 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
wrote:
> On Dec 18, 8:02pm, Pablo Lalloni wrote:
> }
> } words=(${(z)$(</proc/meminfo)})
> }
> } Which set words with the array of all the words in the file and that's
> } great.
> }
> } lines=(${(f)$(</proc/meminfo)})
> }
> } But then I get an array with just one string containing all the lines
> } concatenated (no NLs).
>
> That's happening because $(</proc/meminfo) has replaced all the NLs with
> spaces before (z) or (f) begin working. (z) doesn't care because it
> splits on shell-syntax whitespace, but (f) has nothing to split on.
>
> To get what you want, you have to quote the $(...) substitution so the
> NLs are preserved:
>
> lines=(${(f)"$(</proc/meminfo)"})
>
> That would be "more correct" in the (z) use as well, just in case the
> line breaks were e.g. inside quoted strings that would change the shell
> parse. (Not an issue with /proc/meminfo, of course, but in general.)
>
> } Note that if you split the last assignment in 2 steps, it works as
> expected:
> }
> } lines=$(</proc/meminfo)
> } lines=(${(f)lines})
>
> There you've done first an assignment to a scalar, which preserves the
> NLs as if $(...) were quoted.
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author