bug-bash
[Top][All Lists]
Advanced

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

Re: "unset x[0], a BASH bug?"


From: Oğuz
Subject: Re: "unset x[0], a BASH bug?"
Date: Thu, 6 May 2021 10:42:36 +0300

6 Mayıs 2021 Perşembe tarihinde Ulrich Windl <
Ulrich.Windl@rz.uni-regensburg.de> yazdı:
>
> But why is $# decremented after the first unset?
>

Because `x[0]' existed then, and the number of x's members changed with its
removal. `${#x[@]}' doesn't give you the top index of `x', it expands to
the number of elements in `x'. I suspect you don't know that bash arrays
can be sparse. Well, they can be.

    $ x=([42]=foo [69]=bar)
    $ echo "${#x[@]}"
    2
    $ echo "${!x[@]}"
    42 69
    $ echo "${x[@]}"
    foo bar


-- 
Oğuz


reply via email to

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