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 29319
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: linuxtechguy@xxxxxxxxx
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: subscript not working as "I" expected it would
- Date: Sat, 4 Nov 2023 09:48:28 +0100
- Archived-at: <https://zsh.org/users/29319>
- In-reply-to: <CAN=4vMowpVVYPfkeTnwXEbUUU48UNMwPGnjGi3wWYFVkx21YdA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CA+rB6GLiYbd9EO8_5vRowq09AWsQ3McCzR0D3k6GTXbzhM5m0w@mail.gmail.com> <CAN=4vMowpVVYPfkeTnwXEbUUU48UNMwPGnjGi3wWYFVkx21YdA@mail.gmail.com>
[cc:zsh-users]
On Sat, Nov 4, 2023 at 9:47 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Sat, Nov 4, 2023 at 8:09 AM Jim <linux.tech.guy@xxxxxxxxx> wrote:
> >
> > After beating my head for a while, it dawned on me to try quoting
> > print -- ${"$(<.git/${(s.: .)$(<.git/HEAD)[2]})"[1,9]}
> > which worked, returning the first 9 characters of the hash.
> >
> > Could someone explain why the quotes are needed here so hopefully
> > the next time I will understand. I swear zsh quoting will drive me nuts.
>
> $(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
>
> Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author