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

Re: bash conversion trouble.



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.



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