From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10804 invoked by alias); 23 Aug 2014 18:03:18 -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: 19032 Received: (qmail 3038 invoked from network); 23 Aug 2014 18:03:16 -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 X-Originating-IP: [86.6.157.246] X-Spam: 0 X-Authority: v=2.1 cv=C8BnyG/+ c=1 sm=1 tr=0 a=BvYiZ/UW0Fmn8Wufq9dPrg==:117 a=BvYiZ/UW0Fmn8Wufq9dPrg==:17 a=NLZqzBF-AAAA:8 a=Ec5pgWQj19kA:10 a=bhSIdNy7wQ8A:10 a=uObrxnre4hsA:10 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=pGLkceISAAAA:8 a=bBwDkSI_FWDHbZmkHqgA:9 a=CjuIK1q_8ugA:10 a=I6wTmPyJxzYA:10 a=MSl-tDqOz04A:10 Date: Sat, 23 Aug 2014 19:03:13 +0100 From: Peter Stephenson To: Zsh Users Subject: Re: zsh array subscripting with ksh comp behaviour Message-ID: <20140823190313.0286796f@pws-pc.ntlworld.com> In-Reply-To: References: X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 21 Aug 2014 12:47:28 -0700 Bart Schaefer wrote: > On Aug 21, 2014 6:57 AM, "Jerry Rocteur" wrote: > > > > I have noticed something strange, it is easy to solve but should this > > really be default behaviour, I thought I'd report it. > > > > ] arr=(one two three) > > ] echo ${arr[0]} > > one > > ] echo ${arr[1]} > > one > > Is the behavior you find strange (a) that ${arr[0]} is "one" or (b) that > ${arr[1]} is not "two"? > > If (a) you may be happy to hear that this has been changed in more recent > zsh releases, so that (without ksharrays set) ${arr [0]} is the empty > string, as with any other index that is outside the array bounds. Right --- see the documentation of the option KSH_ZERO_SUBSCRIPT Treat use of a subscript of value zero in array or string expressions as a reference to the first element, i.e. the element that usually has the subscript 1. Ignored if KSH_ARRAYS is also set. If neither this option nor KSH_ARRAYS is set, accesses to an element of an array or string with subscript zero return an empty element or string, while attempts to set element zero of an array or string are treated as an error. However, attempts to set an otherwise valid subscript range that includes zero will succeed. For example, if KSH_ZERO_SUBSCRIPT is not set, array[0]=(element) is an error, while array[0,1]=(element) is not and will replace the first element of the array. This option is for compatibility with older versions of the shell and is not recommended in new code. Hence you can test directly for this feature. As long as the shell isn't old enough that the special parameters used by the new completion system are absent, zmodload -i zsh/parameter print ${+options[kshzerosubscript]} pws