[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Using PE to specify an array
From: |
Bruce Hohl |
Subject: |
Re: [Help-bash] Using PE to specify an array |
Date: |
Fri, 14 Sep 2018 01:34:28 -0400 |
I retract my question as some trial & error with quoting revealed this:
$ var1='ugly_hash'; declare -a _$var1; _ugly_hash+=(123);
$ declare -p _$var1
declare -a _ugly_hash=([0]="123")
# QUOTES ADDED ON RIGHT SIDE addresses the problem
$ declare -a _$var1+="(456)"
$ declare -p _$var1
declare -a _ugly_hash=([0]="123" [1]="456")
# I DID EXPECT THIS TO WORK as it seems to expand as desired.
$ _$var1+="(789)"
bash: _ugly_hash+=(789): command not found
# AND the expansion works when used 'literally'
$ _ugly_hash+=(789)
$ declare -p _$var1
declare -a _ugly_hash=([0]="123" [1]="456" [2]="789")
On Fri, Sep 14, 2018 at 1:09 AM Bruce Hohl <address@hidden> wrote:
> Hello List & thanks for any comments on this:
>
> These commands work:
> var1='ugly_hash'; declare -a _$var1; _ugly_hash+=(123);
>
> But this does not:
> _$var1+=(456); Error = "bash: syntax error near unexpected token `456'"
>
> Question:
> Is there a way to specify _ugly_hash using Parameter Expansion of $var1?
> In the above I desired _$var1 to expand to _ugly_hash in order to add (+=)
> an additional element to that array.
>
Re: [Help-bash] Using PE to specify an array, Greg Wooledge, 2018/09/14