help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistency between how subscripting works with the @ array vs. an


From: Stan Marsh
Subject: Re: Inconsistency between how subscripting works with the @ array vs. an actual array
Date: Mon, 11 May 2026 06:44:18 -0600

From:   Greg Wooledge
Subject: Re: Inconsistency between how subscripting works with the @ array vs. 
an actual array
Date:   Sun, 10 May 2026 17:15:58 -0400

>On Sun, May 10, 2026 at 14:09:51 -0600, Stan Marsh wrote:
>> And note that my specific complaint is that ${@:1} should skip the
>> first element (i.e., start with the second one), but it does not.
>> You have to (non-intuitively) code ${@:2} to start with the second
>> element.
>> 
>> Another way to see this is that $@ and ${@:1} give the same result.

>This isn't going to change.  It works this way because the positional
>parameters are "one-indexed" (they start with 1 instead of 0).

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).

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.

>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.

>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.

Note, incidentally, that the upshot of all of this is that the only
way to fix these sorts of problems is via updating the documentation.
You can't change the code.

I'm not upset about this, but I do find it weird.  Incidentally, I
suggest that we implement a policy that bug-bash is for actual code
bugs only and that documentation bugs (such as the last few threads
I've posted on) should go in help-bash.  Makes sense to me...

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic
answers.  If you have nothing useful to say, then just click Next and go on.
Note that certain posters (e.g., one with initials "GW") seem incapable
of posting non-bureaucratic answers to my posts.  These posters should
definitely just click Next and move on.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]