Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: subscript not working as "I" expected it would
- X-seq: zsh-users 29322
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: linuxtechguy@xxxxxxxxx
- Cc: zsh-users@xxxxxxx
- Subject: Re: subscript not working as "I" expected it would
- Date: Sat, 04 Nov 2023 12:37:20 -0400
- Archived-at: <https://zsh.org/users/29322>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <CAN=4vMpOj=YFjUA8-o24htG_G644c1=bepOTu_V4PSJCV9eBtQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CA+rB6GLiYbd9EO8_5vRowq09AWsQ3McCzR0D3k6GTXbzhM5m0w@mail.gmail.com> <CAN=4vMowpVVYPfkeTnwXEbUUU48UNMwPGnjGi3wWYFVkx21YdA@mail.gmail.com> <CAN=4vMpOj=YFjUA8-o24htG_G644c1=bepOTu_V4PSJCV9eBtQ@mail.gmail.com>
On Sat, Nov 4, 2023, at 4:48 AM, Roman Perepelitsa wrote:
>> $(list) expands to an array. ${$(list)[N]} gives the Nth element of the array.
>>
>> % print -r -- ${$(print foo bar)[1]}
>> foo
>> % print -r -- ${$(print foo bar)[2]}
>> bar
>>
>> $(list) can be an array with just one element but it's still an array.
>> This is the case in your code snippet.
>>
>> "$(list)" on the other hand is a scalar. ${"$(list)"[N]} gives the Nth
>> character.
>>
>> % print -r -- ${"$(print foo bar)"[1]}
>> f
>> % print -r -- ${"$(print foo bar)"[2]}
>> o
Also note that subscripting occurs *before* (s) is applied, so your
(s.: .) is not doing what you think it is doing.
% printf '<%s>' ${(s.: .)$(echo a b: c d)[2]}; echo
<b:>
% printf '<%s>' ${${(s.: .)"$(echo a b: c d)"}[2]}; echo
<c d>
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author