[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Smart determination of array or associative array based
From: |
Chris F.A. Johnson |
Subject: |
Re: [Help-bash] Smart determination of array or associative array based on the first key |
Date: |
Sun, 13 Oct 2019 20:21:49 -0400 (EDT) |
User-agent: |
Alpine 2.21 (DEB 202 2017-01-01) |
On Mon, 14 Oct 2019, Peng Yu wrote:
Bash currently can not use the value of the first key to automatically
determine whether an array or an associative array should be
initialized.
$ x[xxx]=s
$ declare -p x
declare -a x=([0]="s")
In the above example, I'd like `declare -A x` be implicitly called
before `x[xxx]=s` as the key `xxx` is not a number.
What if xxx=6 ?
$ xxx=6
$ x[xxx]=whatever
$ declare -p x
declare -a x=([6]="whatever")
--
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)