Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bash conversion trouble.



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.



Messages sorted by: Reverse Date, Date, Thread, Author