help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Why empty key is not allowed?


From: Peng Yu
Subject: Re: [Help-bash] Why empty key is not allowed?
Date: Sat, 21 Sep 2019 19:31:17 -0500

Another problem is that when the key is empty, the value can not be
empty. I don't understand the rationale of having this as an error. It
is more intuitive to allow empty value no matter what the keys are.

$ declare -A x
$ x[""]=
-bash: x[""]: bad array subscript
$ x[a]=


On 9/21/19, Chris F.A. Johnson <address@hidden> wrote:
> On Sat, 21 Sep 2019, Peng Yu wrote:
>
>> Hi,
>>
>> I am trying to assign an empty key to an associated array.
>>
>> $ declare -A x
>> $ x[]=1
>> -bash: x[]: bad array subscript
>>
>> But I got this error. Is it not allowed? Or I am not doing it correctly?
>>
>> The manpage says this. So empty string should be allowed?
>>
>> "associative arrays are referenced using arbitrary strings."
>
> And empty string IS allowed. You are not using any string; that is not
> allowed.
>
> x[""]=1
>
>
> --
>     Chris F.A. Johnson                         <http://cfajohnson.com/>
>     =========================== Author: ===============================
>     Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
>     Pro Bash Programming: Scripting the GNU/Linux shell (2009, Apress)
>


-- 
Regards,
Peng



reply via email to

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