Path: csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: konsolebox Newsgroups: gnu.bash.bug Subject: Re: Assignment of associative arrays through braces Date: Wed, 1 Aug 2018 00:53:38 +0800 Lines: 38 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1533056064 26808 208.118.235.17 (31 Jul 2018 16:54:24 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: Chester Ramey Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fTvEfKHJ64oyZxTfc5OZ5+ErXKA9BudYNhIwgze7fj4=; b=AxseZgxI+Hwghz4M4bMnZU/IpMErzCvLXXTykGyECTl5HceVbSIROc7Pa9El5NESDn 7OGvzNueKwgN9+6EPmMIyNLqNOY03qpuAvx5GbUi3UwOLEZzCUCvhKKLJBwV7ZrHjv0p vdCm6F9DI7iLzwvSTbAe6hqgAC784YXxNKp+EGwWrW6tjR5d9BO/qjzLdZDw1BsMPeW3 cA13gwYsWtbPtCBrYhoTmCdMralzbScYHCBs2ZnPAzmxsFfznI2b4Ay5P1JQ4/ptmzje 8VJ8DtnDHN59p5eSel9itFKS1xTeR6hd4tf1NvZ2QAwMqFrlZNFOLntX6xJI8rmmK01P wBzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fTvEfKHJ64oyZxTfc5OZ5+ErXKA9BudYNhIwgze7fj4=; b=cU6XSzBthilM44QeWbD1TsHA4Yc8z5+5vBZ2qTYgyZecfYdThef9JlaUfBtRqCaGkK cx+guhzB1ZA92aDYOe5utRnlzwTK+/Yqigfz61GtUISG/R0KCI+LAdL13vHjotdeZeQY bHsRucmQmmnvL+NJzuvzRvZIxEnrSHnhWEEi048DEcQY6l84He2vle6gmz1IZADKEPIs u9/BrcyU3jLDMEq551OpzarnQXKgA8Dq7UgGDe7ocklLcBFH5wU4SBPFYD++9DfsGswD FfIq0ejs42KwIe6VidtUHXYO1dRhHoQKpYBm5ztP6xceEYizKHQNKPADuegGRNC8ctEn WkIw== X-Gm-Message-State: AOUpUlGKkT/gMqz/y8UeCYjYHT2/Dkn78u53ylVaXky2lAbWT8tmQSyj eeSUDvkv/iy3atQWUImL0Z8A/5oBdmwRX++1q8s= X-Google-Smtp-Source: AAOMgpdhc49eai49YNTP/CEKsnsz0T+YbeNLaYy69Zvh9sKHZEZISYp5rmK9WHolec8Vkw63P0581NzXlJGP+wt2jXs= X-Received: by 2002:a24:36c5:: with SMTP id l188-v6mr402186itl.125.1533056058837; Tue, 31 Jul 2018 09:54:18 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::234 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14426 On Tue, Jul 31, 2018 at 10:31 PM, Chet Ramey 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