Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

(z) word splitting on one word



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: signature.asc
Description: OpenPGP digital signature



Messages sorted by: Reverse Date, Date, Thread, Author