From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1037 invoked by alias); 25 Feb 2017 19:43:21 -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: 22496 Received: (qmail 26138 invoked from network); 25 Feb 2017 19:43:21 -0000 X-Qmail-Scanner-Diagnostics: from mta01.eastlink.ca 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(24.224.136.30):SA:0(-0.7/5.0):. Processed in 2.44284 secs); 25 Feb 2017 19:43:21 -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=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.eastlink.ca designates 24.224.136.30 as permitted sender) X-Authority-Analysis: v=2.2 cv=DOfN2GFb c=1 sm=1 tr=0 a=XjFz1dxMm4jRJ7U1/4sCTg==:117 a=XjFz1dxMm4jRJ7U1/4sCTg==:17 a=N659UExz7-8A:10 a=cxtdDp0LCklqowhVCq4A:9 a=pILNOxqGKmIA:10 X-EL-IP-NOAUTH: 24.207.24.32 Subject: Re: bash conversion trouble. To: zsh-users@zsh.org 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> From: Ray Andrews Message-id: Date: Sat, 25 Feb 2017 11:13:10 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-version: 1.0 In-reply-to: <170225090218.ZM22334@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 25/02/17 09:02 AM, Bart Schaefer wrote: > 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. > > When invoking a script e.g. "prog this is a test", internally $0 is > "prog" and the arguments are $1 = this, $2 = is, etc. Therefore when > referring to the positional paramters, counting always starts from 1. > Consequently it "makes sense" to have other arrays also count from 1, > so that e.g. > > newarray=("$@") > if [ "$newarray[1]" = "$1" ]; then echo copied correctly; fi > > It's strange to have to adjust thinking to zero-based for other arrays > when the most obvious default array seems to start at 1. > Interesting. So bash and ksh went one way an zsh and csh went the other. Obviously the decision was made in the context of the time, but I'd have expected zsh to go with bash. One hears nothing but bad things about csh. But it's good to stop looking for some deep logic to it and just realize that it's arbitrary. The only real irritation is that it isn't consistent. Yeah, why not just use natural counting? That array[9] is the tenth element has always seemed a bit dumb but I'm used to it from C.