Re: Inconsistency between how subscripting works with the @ array vs. an
From:
Zachary Santer
Subject:
Re: Inconsistency between how subscripting works with the @ array vs. an actual array
Date:
Mon, 11 May 2026 11:53:59 -0400
On Mon, May 11, 2026 at 8:44 AM Stan Marsh <gazelle@xmission.com> wrote:
>
> Of course, it isn't going to change. It is well-established on this
> board that you can't ever change how things work in the shell because
> it would break existing code. In fact, as I made clear, changing this
> now would break some of my code (where I have coded around the problem).
What problem did this cause you?
> Note, incidentally, that other scripting languages, e.g., Perl,
> Python, are not so restrained. These languages are free to make
> breaking changes - essentially, each new (major) version is a new
> language.
This behavior, at least, is definitely specified by POSIX. Neither
Perl nor Python have a standard they're written to follow.
> >In other words, $1 is the first positional parameter, not the second.
>
> Not really, when you consider that $0 is there as the zeroth element.
> You can see that from one of the example lines in the OP.
$0 doesn't represent an argument passed to the script or function. It
shows up in the Special Parameters section of the manual, whereas
Positional Parameters tells us "A positional parameter is a parameter
denoted by one or more digits, other than the single digit 0."
> >The goal is to be consistent with the way $1 works, not with the
> >way ${array[1]} works.
>
> I get that, but I still think it is wrong. But I do realize that it
> cannot and will not be fixed. It should be documented, though.
It is. "@ ($@) Expands to the positional parameters, starting from one."