Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16735
| Path | csiph.com!goblin3!goblin.stu.neva.ru!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Eli Schwartz <eschwartz@archlinux.org> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Syntax error in a Map/Hash initializer -- why isn't this supported? |
| Date | Mon, 10 Aug 2020 18:44:02 -0400 |
| Lines | 115 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1488.1597099463.2739.bug-bash@gnu.org> (permalink) |
| References | <CALOnQv74zqDBOQoSRhH07oQ7eu5qLsdzU8r4d48==eZhB4YE3g@mail.gmail.com> <ad562bc9-4ca4-2b50-c1f8-2fe8d30653b3@archlinux.org> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="TdfmH8XLHPEYRadhDYWdlXhD4gsyEvALq" |
| X-Trace | usenet.stanford.edu 1597099464 12726 209.51.188.17 (10 Aug 2020 22:44:24 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| X-Spam-BL-Results | |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1597099445; bh=6V2nZ1gDYJC86hUiZzmu16deKx5H/vuTFMdpVFiocR4=; h=Subject:To:References:From:Date:In-Reply-To; b=FeIJlV4ko/sykwFa+sTrtm7Fknz/DbOREADrkNbyJ8auqAwArcAXvNr4sIV8AXxeD 2EDs08mie3JNIAae3M65iYxkU+9Vwr57BAM2LiWNWKsS/7K/FMgbnOyYIPebm8QTbI /fzcYXBmUkTHh9/vg7lmikyUeUIX6R0Dn3nFws0IFWaOoLjkeVEAWy+BtZJc2nCDVs mwjuyzK0td7bWipk+7k+/PZ2ysyHj0NBvKgRO1TvTrZ+TgNeJHdv94EPsfXWPyh7a0 CW+AGNBDizonCKJAM5EXSOThuJCKwUampKe5m8z0o1s1EsiExxAHUYqpr3+sIG2FTi oM7S5/HSknSpqLqoFPeIWkYFBxLKpmLg7TrpQty8i4TBuKS775VeL8Wf/UkGnLUX0w yCwRcw3R0NNH/m6oyI6zn/8DtoICJj5Pt2070t1qJ7FTU2nWIRbkri+ehjJZ43tzu4 +sV027QzA83OWfQLxMOl9WogsD7dxlUzJiPG4Oo0eXu8A+lxrT+4D0ylMAXJrVuMgx JeudtRVhK8APIhC6Sf2FnXZBwh6LH/UOfy6ZoCF26Yd7gAq/6Hk0qXAL0OCvDK1O5Y cgF5LdgrB6M19uXBcExCDyOSlskKbA3KS/RyUMN7zOoOrWBjXhjS08I32DM4a1HuZk 6Qv60UMO0sKMUfFL93DQsWA4= |
| X-Clacks-Overhead | GNU Terry Pratchett |
| In-Reply-To | <CALOnQv74zqDBOQoSRhH07oQ7eu5qLsdzU8r4d48==eZhB4YE3g@mail.gmail.com> |
| Received-SPF | pass client-ip=2a01:4f8:160:6087::1; envelope-from=eschwartz@archlinux.org; helo=orion.archlinux.org |
| X-detected-operating-system | by eggs.gnu.org: No matching host in p0f cache. That's all we know. |
| X-Spam_score_int | -53 |
| X-Spam_score | -5.4 |
| X-Spam_bar | ----- |
| X-Spam_report | (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 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 | <ad562bc9-4ca4-2b50-c1f8-2fe8d30653b3@archlinux.org> |
| X-Mailman-Original-References | <CALOnQv74zqDBOQoSRhH07oQ7eu5qLsdzU8r4d48==eZhB4YE3g@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:16735 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 8/10/20 5:56 PM, L A Walsh wrote:
> 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"
Correct, bash does not implement multidimensional arrays and its syntax
error if you try anyway, implements the minimum heuristics necessary to
convey that fact to you.
> 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?
.. I'm sorry, did you just state your disapproval at bash for not
implementing something, but having a useful error message in the
process? Would you prefer "bash: error: an unknown error occurred"?
> Some nested constructs seem to work:
>> b=(1 2 3)
>> a=(4 5 6)
>> echo ${a[${b[1]}]}
> 6
This is not a multidimensional array, obviously. It is two
single-dimensional arrays, with a value lookup in one array that is then
reused as the input key to perform another lookup in the second array.
> but more often than not, they don't. Is there a reason to disallow such?
Today's session of "Linda Walsh is year-by-year terrible at asking
questions".
Instead of asking:
"Can bash please implement multidimensional arrays as I think they're
nifty and would like to use them."
We are getting:
"Bash supports multidimensional arrays because $HACK but it doesn't let
me do them in X Y Z manner, is there a reason to arbitrarily forbid them
or can this pointless restriction be lifted."
This is a variant of http://catb.org/~esr/faqs/smart-questions.html#symptoms
Please read the whole article, but pay particular attention to the
section on "don't describe your problem in terms of the incorrect
diagnostic theory you've already decided is the real problem".
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
Back to gnu.bash.bug | Previous | Next | Find similar
Re: Syntax error in a Map/Hash initializer -- why isn't this supported? Eli Schwartz <eschwartz@archlinux.org> - 2020-08-10 18:44 -0400
csiph-web