Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15185
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | L A Walsh <bash@tlinx.org> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Unexpected result of array assignment |
| Date | Wed, 17 Jul 2019 22:46:00 -0700 |
| Lines | 38 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1622.1563428772.2688.bug-bash@gnu.org> (permalink) |
| References | <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> <5D300798.1040708@tlinx.org> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | usenet.stanford.edu 1563428773 11732 209.51.188.17 (18 Jul 2019 05:46:13 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | bug-bash@gnu.org |
| To | "Darren 'Tadgy' Austin" <darren@afterdark.org.uk> |
| Envelope-to | bug-bash@gnu.org |
| User-Agent | Thunderbird |
| In-Reply-To | <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] |
| X-Received-From | 173.164.175.65 |
| 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 | <5D300798.1040708@tlinx.org> |
| X-Mailman-Original-References | <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> |
| Xref | csiph.com gnu.bash.bug:15185 |
Show key headers only | View raw
On 2019/07/17 18:16, Darren 'Tadgy' Austin wrote:
> Repeat-By:
> declare -A foo
> foo=(["key"]="value1")
> declare -p foo
> foo=(["key"]="${foo["key"]} value2")
> declare -p foo
>
> The above should result in 'foo["key"]' having a value of 'value1 value2', but the result is simply ' value2', which I believe to be incorrect behaviour.
>
In bash4.4.12, Using:
I think you need to tell bask that you are updating 'foo'
instead of assigning to it:
This seems to do what you want:
foo+=([key]="${foo[key]} value2")
> my -p foo
declare -A foo=([key]="value1 value2" )
or w/quotes:
foo+=(["key"]="${foo["key"]} value3")
> my -p foo
declare -A foo=([key]="value1 value2 value3" )
I think that without the update it becomes an assign and clears
the value assigned to 'key' before using it to form the string.
It certainly isn't intuitive, but I don't know if there is a
guarantee of it picking up the value of "foo[key]" before initializing
the target space.
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Unexpected result of array assignment L A Walsh <bash@tlinx.org> - 2019-07-17 22:46 -0700
csiph-web