Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14426 > unrolled thread
| Started by | konsolebox <konsolebox@gmail.com> |
|---|---|
| First post | 2018-08-01 00:53 +0800 |
| Last post | 2018-08-01 00:53 +0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Assignment of associative arrays through braces konsolebox <konsolebox@gmail.com> - 2018-08-01 00:53 +0800
| From | konsolebox <konsolebox@gmail.com> |
|---|---|
| Date | 2018-08-01 00:53 +0800 |
| Subject | Re: Assignment of associative arrays through braces |
| Message-ID | <mailman.4481.1533056063.1292.bug-bash@gnu.org> |
On Tue, Jul 31, 2018 at 10:31 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> On 7/27/18 7:13 PM, konsolebox wrote:
>> Hi Chet,
>>
>> I wonder if you can allow bash to have another syntax to allow simpler
>> declaration and/or definition of associative arrays. The changes
>> needed to have it done seem simple enough, and the only conflict it
>> makes is a scalar `var={...` assignment, which in my opinion is better
>> quoted to make it more readable and less questionable from other
>> syntaxes like brace expansion. I believe most people intuitively
>> quotes it, and assignments that start with `{` is fairly rare.
>
> So it's syntactic sugar for `declare -gA a; a=( ... )'?
That surely is one of the main goals, but it's not exact. `declare
-gA a; a=(...)` would always affect the main global scope.
Example:
$ g() { declare -gA a=([x]=y); }; f() { local -A a=(); g; declare -p
a; }; declare -A a=([a]=b); f; declare -p a
declare -A a=()
declare -A a=([x]="y" )
But as shown in my earlier example, a={...} would only affect the
nearest scope which was local a={}.
This proposal simply requests an intuitively equivalent simple
assignment syntax for associative arrays just like a='...' and
a=(...), with same behavior for scoping.
Maybe we can add another option like -G to have similar effect but
that's a little different already. Just allowing a={} would make it
simpler for every scripter.
--
konsolebox
Back to top | Article view | gnu.bash.bug
csiph-web