Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh parameter expansion replacement pattern parses string differently if its input is a variable instead of inlined
- X-seq: zsh-users 24722
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: <zsh-users@xxxxxxx>
- Subject: Re: zsh parameter expansion replacement pattern parses string differently if its input is a variable instead of inlined
- Date: Wed, 11 Mar 2020 10:13:34 +0000
- Cms-type: 201P
- Dkim-filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200311101335euoutp02bc84aeef7fe3f712d080f42c42f4ece6~7OFFS4KAt2082520825euoutp02H
- In-reply-to: <CAAEcvMp4D3zna84wGR5AhQWY5Q-XDA1cWEP4982qQ=qY2i7qbw@mail.gmail.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>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20200310200552eucas1p283e8a92d686e34198f78b647370f5a24@eucas1p2.samsung.com> <CAAEcvMp4D3zna84wGR5AhQWY5Q-XDA1cWEP4982qQ=qY2i7qbw@mail.gmail.com>
On Tue, 2020-03-10 at 16:04 -0400, Ross Goldberg wrote:
> How can I inline the curl call yet still filter out the 3 values?
>
> #!/usr/bin/env zsh
>
> setopt EXTENDED_GLOB
>
> # variable: 3 values are correctly filtered out
> versions=$(curl '--silent' '--location' '
> https://protect2.fireeye.com/url?k=1c92524f-415c53fb-1c93d900-000babdfecba-907de8ae2883278c&u=https://api.sdkman.io/2/candidates/groovy/darwin/versions/list?current=2.5.8&installed=2.5.8
> ')
> printf -- '%s\n' ${${(Z+n+)versions//[*+>][ *+>]# [[:graph:]]##}}
>
> # inlined: 3 values are not filtered out
> printf -- '%s\n' ${${(Z+n+)$(curl '--silent' '--location' '
> https://protect2.fireeye.com/url?k=7fed1228-2223139c-7fec9967-000babdfecba-dd90873f5cc32e48&u=https://api.sdkman.io/2/candidates/groovy/darwin/versions/list?current=2.5.8&installed=2.5.8')//[*+>][
> *+>]# [[:graph:]]##}}
If I'm following correctly (a simpler example would probably help if I'm
missing the point, though I think what I've done gives what you want),
you need to put double quotes around the "$(curl ...)" part.
printf -- '%s\n' ${${(Z+n+)"$(curl '--silent' '--location' 'https://protect2.fireeye.com/url?k=7fed1228-2223139c-7fec9967-000babdfecba-dd90873f5cc32e48&u=https://api.sdkman.io/2/candidates/groovy/darwin/versions/list?current=2.5.8&installed=2.5.8')"//[*+>][ *+>]# [[:graph:]]##}}
The big difference is that the assignment in the other version is
already turning the value into a single word, whereas in the second case
you will get the output split into a set of words; the substitution then
operates on those words separately, which isn't what you want.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author