Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Splitting into a one element array
- X-seq: zsh-users 20558
- From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Splitting into a one element array
- Date: Mon, 14 Sep 2015 22:06:17 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=FckF3rGcwNheaEyVBa7DfYO2Rvjmug5k8Zz9GFOj/iY=; b=m+rgI7GjzkvB4EMkYYMpVhn13f9j8nl5/YsWMcKR5mU+BSTjxgZVs1A8DGsBvmxVCs FPCKpQ/W8d+VBZ1OTpsJpt8TCj2Vl1ZJQrUuGb7NxtHBRTViA+b3IjE7JbW1MPkJOoo4 V4cspirqBbebbivKIAlBW9Y7B2g36AAE1ulr7c6hrg/VuSyA44DPgwFdoXksNIwQwzOS 1T6hmjMMnavKl90AzX0itJChRwYD3ks19p5YThmgZtC2CAc9EtI+WEPtbVPHleh8YyMw A4BPLv8jJSL2q6CHLjG6JuYCQps7w4A6DThdqs0AXmf+Vta2PoCK867eBIqpOWmoSEoL NSmQ==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
I am writing a function where I want to split the $LBUFFER on whitespace,
and then handle the last element in the resulting array. My initial attempt
looked like this:
local dir=${${(z)LBUFFER}[-1]}
This works if $LBUFFER contains more than one word, but fails if it is one
word only. I tested the behavior with the following function:
trysplit() {
local astring="aaa bbb"
print -l ${=astring}
print
print -l ${${=astring}[-1]}
print
local cstring="ccc"
print -l ${=cstring}
print
print -l ${${=cstring}[-1]}
}
with this result:
% trysplit
aaa
bbb
bbb
ccc
c
So, my interpretation of the above is that IF the split results in only one
word, the result is not handled as an array with one element, but as a
regular string. And then only the first letter of the $cstring is printed.
Is there some way to handle this that I have missed, or do I need to check
the split result for size, and then treat the one-element case differently?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author