Sample Header Ad - 728x90

Is there a reason why the first element of a Zsh array is indexed by 1 instead of 0?

47 votes
2 answers
18344 views
From my experience with modern programming and scripting languages, I believe most programmers are generally accustomed to referring to the first element of an array as index 0 (zero). I'm sure I've heard of languages other than zsh starting array indexing on 1 (one); it's okay, as it is equally convenient. However, as the previously released and widely used shell scripting languages ksh and bash both use 0, why would someone choose to alter this common convention? There does not seem to be any substantial advantages of using 1 as the first index; then, the only explanation I can think of regarding this somewhat "exclusive feature" to shells would be "they just did this to show off a bit more their cool shell". I don't know much of either zsh or its history, though, and there is a high chance my trivial theory about this does not make any sense. Is there an explanation for this? Or is it just out of personal taste?
Asked by deekin (650 rep)
Dec 30, 2015, 05:11 PM
Last activity: Nov 16, 2024, 09:50 AM