From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29970 invoked by alias); 28 Feb 2017 16:36:08 -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: 22517 Received: (qmail 737 invoked from network); 28 Feb 2017 16:36:07 -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.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(195.159.176.226):SA:0(2.7/5.0):. Processed in 1.858494 secs); 28 Feb 2017 16:36:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: ** X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NML_ADSP_CUSTOM_MED,RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 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: Stephane Chazelas Subject: Re: bash conversion trouble. Date: Tue, 28 Feb 2017 15:56:01 +0000 Message-ID: <20170228155601.GB16082@chaz.gmail.com> References: <004ec4f2-3b3a-8907-86a6-4326399783aa@eastlink.ca> <170224204153.ZM19840@torch.brasslantern.com> <6f722b8f-a712-985f-65e8-3b03a5b352c3@eastlink.ca> <170225075521.ZM22115@torch.brasslantern.com> <32f48d32-2b11-045e-5925-8f112783f1e2@eastlink.ca> <170225090218.ZM22334@torch.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@blaine.gmane.org User-Agent: Mutt/1.5.24 (2015-08-30) Content-Disposition: inline In-Reply-To: <170225090218.ZM22334@torch.brasslantern.com> 2017-02-25 09:02:18 -0800, Bart Schaefer: > On Feb 25, 8:24am, Ray Andrews wrote: > } > } Just curious: why would that have been changed? > > This comes from zsh's original heritage as a bourne-shell-like shell > intended for students who were trained on BSD csh. Also this happened > before ksh was widely available outside an AT&T research lab so there > was no bourne-shell array syntax to "change". > > Exactly why csh adopted 1-based arrays is probably lost to history at > this point, but I suspect the argument goes something like this. [...] See also https://unix.stackexchange.com/questions/252368/is-there-a-reason-why-the-first-element-of-a-zsh-array-is-indexed-by-1-instead-o/252405#252405 pasted below for convenience: - Virtually all shell arrays (Bourne, csh, tcsh, fish, rc, es, yash) start at 1. ksh is the only exception that I know (bash just copied ksh). - Most interpreted languages at the time (early 90s): awk, tcl at least, and tools typically used from the shell (cut -f1-3, head -n 3, sort -k1,3, cal 1 2015, comm -1) start at 1. sed, ed, vi number their lines from 1... - zsh takes the best of the Bourne shell and csh. The Bourne shell array $@ start at 1. zsh is consistent with its handling of $@ (like in Bourne) or $argv (like in csh). See how confusing it is in ksh where ${@:0:1} does not give you the first positional parameter for instance. - A shell is a user tool before being a programming language. It makes sense for most users to have the first element in $a[1]. It also means that the number of elements is the same as the last indice (in zsh like in most other shells except ksh, arrays are not sparse). - a[1] for the first element is consistent with a[-1] for the last. So IMO the question should rather be: what got into David Korn's head to make its arrays start at 0?