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?

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
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 Mon, 10 Aug 2020 14:56:47 -0700
Lines 25
Approved bug-bash@gnu.org
Message-ID <mailman.1482.1597096632.2739.bug-bash@gnu.org> (permalink)
References <CALOnQv74zqDBOQoSRhH07oQ7eu5qLsdzU8r4d48==eZhB4YE3g@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1597096633 11075 209.51.188.17 (10 Aug 2020 21:57:13 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rzV6z3lt7nfHXXsXP/3C0ovXsMpBr0A8MHG7bbTPA+g=; b=WHat1ickSE7Bc1kexg4XHanQl50EIGRyu3qd6YayO4xeiDcMRDUGAoIzcPJvN0578v xeZnEG/rQDVxgVO3snS3/zsB24v9WLp87uaNdQ9/GEW5wp1OIvFP9AnOHPPg8Te2V6Kr rlwb1GGmgJrncCPlwJgBD138twmhZCq5Ivz2FPHJoHL63F9SiZD3rTisruyODX/Qus4O Ss+vGfNkOxLE0542yU5mXGdmIM3SriB31E/WIRbXQj3o1nwD0l/6NAqFrTRnaFDcizcc 4ytmnQgfN1UZJ9hHYaG/hAzjWfoctIS6JRR8uJMQkguu2wENXC3nMqftXAts4r/7ikba AtgA==
X-Gm-Message-State AOAM530kBcGxteNpmnGPLGYPr5FPvk53XS2MVMbz0h2Tj25255gaTpZa 6OY0CYTTLNW/xN00RpGQ4AZbqcEuD/zmvYbJ0lJoF0OU4/o=
X-Google-Smtp-Source ABdhPJzdayIOewKDMV+ctHd3jcPWx0PSJmExOsyoUGlGJuIsmL1EosS1zfoAfSAX5qOlVc0LSBfr5zi+yG9zZPiZP2Y=
X-Received by 2002:a92:a1d7:: with SMTP id b84mr6855109ill.75.1597096619886; Mon, 10 Aug 2020 14:56:59 -0700 (PDT)
Received-SPF softfail client-ip=209.85.166.173; envelope-from=gsuite@tlinx.org; helo=mail-il1-f173.google.com
X-detected-operating-system by eggs.gnu.org: First seen = 2020/08/10 17:57:00
X-ACL-Warn Detected OS = Linux 2.2.x-3.x [generic] [fuzzy]
X-Spam_score_int -21
X-Spam_score -2.2
X-Spam_bar --
X-Spam_report (-2.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=ham autolearn_force=no
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CALOnQv74zqDBOQoSRhH07oQ7eu5qLsdzU8r4d48==eZhB4YE3g@mail.gmail.com>
Xref csiph.com gnu.bash.bug:16734

Show key headers only | 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