Skip to content

Index range expansion treats ending index 0 as 1 #8213

@kidonng

Description

@kidonng

fish --version: 3.3.1

Quoting the docs:

List indices start at 1 in fish, not 0 like in other languages.

An invalid index is silently ignored resulting in no value (not even an empty string, just no argument at all).

However, it seems index range expansion treats ending index 0 as 1:

$ set -S LESS
$LESS: set in universal scope, exported, with 4 elements
$LESS[1]: |-R|
$LESS[2]: |-i|
$LESS[3]: |-M|
$LESS[4]: |--incsearch|

$ echo $LESS[0]
fish: array indices start at 1, not 0.
echo $LESS[0]
           ^

$ echo $LESS[2..0]
-i -R

$ echo $LESS[2..1]
-i -R

This behavior is, at least for me, unexpected and seems in contrary to what the docs says (it is
an invalid index but doesn't result in no value).

Or in other words, why can the index end with 0 if it can't start at 0?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions