From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21688 invoked by alias); 21 Dec 2011 03:05:37 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30038 Received: (qmail 8985 invoked from network); 21 Dec 2011 03:05:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <111220190511.ZM11868@torch.brasslantern.com> Date: Tue, 20 Dec 2011 19:05:11 -0800 In-reply-to: <4EF13FBA.8080803@eastlink.ca> Comments: In reply to Ray Andrews "bug" (Dec 20, 6:08pm) References: <4EF13FBA.8080803@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: bug MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Dec 20, 6:08pm, Ray Andrews wrote: } } function z } { } var=$1 } echo "var:/${1:0:1}/${1:1:1}/${1:2:1}/" } echo "var:/${var:0:1}/${var:1:1}/${var:2:1}/" } } } } } $ z abcde } } var: /a/a/b/ } var: /a/b/c/ } } How can that be correct? I'm still not sure it's correct, but this explains why it happens: For further compatibility with other shells there is a special case for array offset 0. This usually accesses to the first element of the array. However, if the substitution refers the positional parameter array, e.g. $@ or $*, then offset 0 instead refers to $0, offset 1 refers to $1, and so on. In other words, the positional parameter array is effectively extended by prepending $0. Hence ${*:0:1} substitutes $0 and ${*:1:1} substitutes $1. So :0:1 is acting on the invisible $0 even though the reference is to an individual positional parameter rather than to the positional array.