From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24651 invoked by alias); 14 Sep 2015 20:06:22 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20558 Received: (qmail 21489 invoked from network); 14 Sep 2015 20:06:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 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== MIME-Version: 1.0 X-Received: by 10.152.20.228 with SMTP id q4mr16010641lae.74.1442261177138; Mon, 14 Sep 2015 13:06:17 -0700 (PDT) Date: Mon, 14 Sep 2015 22:06:17 +0200 Message-ID: Subject: Splitting into a one element array From: =?UTF-8?Q?Jesper_Nyg=C3=A5rds?= To: Zsh Users Content-Type: multipart/alternative; boundary=089e01493a0a23065c051fba9904 --089e01493a0a23065c051fba9904 Content-Type: text/plain; charset=UTF-8 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? --089e01493a0a23065c051fba9904--