From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=DATE_IN_PAST_12_24, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id b4e35583 for ; Mon, 1 Apr 2019 09:10:50 +0000 (UTC) Received: (qmail 25022 invoked by alias); 1 Apr 2019 09:10:37 -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: List-Unsubscribe: X-Seq: 23897 Received: (qmail 4155 invoked by uid 1010); 1 Apr 2019 09:10:37 -0000 X-Qmail-Scanner-Diagnostics: from 195.159.176.226 by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.1/25405. spamassassin: 3.4.2. Clear:RC:0(195.159.176.226):SA:0(0.2/5.0):. Processed in 0.829243 secs); 01 Apr 2019 09:10:37 -0000 X-Envelope-From: gcszu-zsh-users@m.gmane.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at m.gmane.org does not designate permitted sender hosts) X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@zsh.org From: Anssi Saari Subject: Re: Confused about splitting Date: Sun, 31 Mar 2019 20:56:03 +0300 Organization: An impatient and LOUD arachnid Message-ID: References: <20190331125813.pd45aqx4bvdjnrgr@tarpaulin.shahaf.local2> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cancel-Lock: sha1:UyHJVl3miAwPjfUlDlLqrc/BLhg= Daniel Shahaf writes: > «${=g}» does split the value of the parameter 'g'; you can see that with > «printf '[%s]' ${=g}». Then, that intermediate result — an array of words — is > assigned to the parameter 'first' scalarly, so the value of $first is set to be > the words of the array joined by spaces as a single string. That's why «echo > $first» has the right output. The «echo $#first» line prints the length of the > string "$first" in characters, because that's what the «$#foo» syntax does when > foo is a scalar. This mistaken idea came from the fact $first[1] is just e with foofunc3. $first[2] is n, $first[3] is o and so on. For some reason I thought scalars don't have that but they do. > The fix is to add back the parentheses to make the assignment an array > assignment: «first=( ${=g} )». Thanks.