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: Chris F.A. Johnson
Subject: Re: [Help-bash] Why empty key is not allowed?
Date: Sat, 21 Sep 2019 19:57:31 -0400 (EDT)
User-agent: Alpine 2.21 (DEB 202 2017-01-01)

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)



reply via email to

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