From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: zsh-users@zsh.org
Subject: Re: bash conversion trouble.
Date: Tue, 28 Feb 2017 15:56:01 +0000 [thread overview]
Message-ID: <20170228155601.GB16082@chaz.gmail.com> (raw)
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?
next prev parent reply other threads:[~2017-02-28 16:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-25 1:35 Ray Andrews
2017-02-25 4:41 ` Bart Schaefer
2017-02-25 15:13 ` Ray Andrews
2017-02-25 15:26 ` Peter Stephenson
2017-02-25 15:55 ` Bart Schaefer
2017-02-25 16:24 ` Ray Andrews
2017-02-25 17:02 ` Bart Schaefer
2017-02-25 19:13 ` Ray Andrews
2017-02-25 20:09 ` Bart Schaefer
2017-02-26 5:05 ` Ray Andrews
2017-02-26 17:19 ` Bart Schaefer
2017-02-26 18:03 ` Ray Andrews
2017-02-26 21:10 ` Shell history (Re: bash conversion trouble.) Bart Schaefer
2017-02-26 23:23 ` Ray Andrews
2017-02-28 15:56 ` Stephane Chazelas [this message]
2017-02-28 19:27 ` bash conversion trouble Ray Andrews
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170228155601.GB16082@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).