Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16734

Syntax error in a Map/Hash initializer -- why isn't this supported?

From L A Walsh <bash@tlinx.org>
Newsgroups gnu.bash.bug
Subject Syntax error in a Map/Hash initializer -- why isn't this supported?
Date 2020-08-10 14:56 -0700
Message-ID <mailman.1482.1597096632.2739.bug-bash@gnu.org> (permalink)
References <CALOnQv74zqDBOQoSRhH07oQ7eu5qLsdzU8r4d48==eZhB4YE3g@mail.gmail.com>

Show all headers | View raw


I wanted to use a map that looked like this:

declare -A switches=([num]=(one two three)), where '(one two three)'
is an associated list.  Ideally, I could access it like other arrays:
for types in  ${switches[num][@]}; do...
or
switches[num]=(one two three)    #gives:
                  -bash: switches[num]: cannot assign list to array member
or
echo ${switches[num][0]}  (="one").

I defaulted to going around it by making it a string, like:
switches[num]="one|two|three"
or
switches[num]="(one two three)" but why?  It seems obvious that bash
knows what I'm trying to do, so why not just do it?

Some nested constructs seem to work:
> b=(1 2 3)
> a=(4 5 6)
> echo ${a[${b[1]}]}
6

but more often than not, they don't.  Is there a reason to disallow such?

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Syntax error in a Map/Hash initializer -- why isn't this supported? L A Walsh <bash@tlinx.org> - 2020-08-10 14:56 -0700

csiph-web