[-- Attachment #1.1: Type: text/plain, Size: 576 bytes --] Hi! I am trying to get the last word of LBUFFER. What I did previously was: ${${(z)LBUFFER}[-1]} This worked flawlessly until I noticed today that it misbehaves if LBUFFER contains only one word. In this case it seems like `[-1]` acts on a scalar, as it expands to the last character instead of LBUFFER as I would expect. Is this expected behaviour? I now work around it by prepending LBUFFER with a dummy word so that it always has at least two words (I know that it is not empty). But this feels very hacky. Do you know of a better way? Julian [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 249 bytes --]
On 9/22/22, Julian Prein <druckdev@protonmail.com> wrote:
> Hi!
>
> I am trying to get the last word of LBUFFER.
>
> What I did previously was:
>
> ${${(z)LBUFFER}[-1]}
>
> This worked flawlessly until I noticed today that it misbehaves if LBUFFER
> contains only one word. In this case it seems like `[-1]` acts on a scalar,
> as
> it expands to the last character instead of LBUFFER as I would expect.
>
> Is this expected behaviour?
>
> I now work around it by prepending LBUFFER with a dummy word so that it
> always
> has at least two words (I know that it is not empty). But this feels very
> hacky.
>
> Do you know of a better way?
${${(Az)LBUFFER}[-1]}
--
Mikael Magnusson
[-- Attachment #1.1.1: Type: text/plain, Size: 72 bytes --] > $\{$\{(Az)LBUFFER\}\[-1\]\} Perfect, thank you very much! Julian [-- Attachment #1.1.2.1: Type: text/html, Size: 77 bytes --] [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 249 bytes --]