help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue declaring an array via a variable name


From: Greg Wooledge
Subject: Re: Issue declaring an array via a variable name
Date: Sat, 14 Aug 2021 19:03:13 -0400

On Sat, Aug 14, 2021 at 04:53:38PM -0500, Hunter Wittenborn wrote:
> variable="hello"
> declare -g "${variable}"=("world" "me")
> 
> When run, it's complaining about a syntax error near "(", appearing to be on 
> the 'declare' line right next to where I start typing the array.

Confirmed.  It "works" with a string assignment, but not with an array
assignment.

> Is there a valid reason why this isn't working (besides it just being a bug)? 

Dunno.

> If there is, is it possible to implement it otherwise so I can use it?

You could use a nameref instead.  That's what they're for.

unicorn:~$ declare -n ref=hello
unicorn:~$ declare -g ref=("world" "me")
unicorn:~$ declare -p ref hello
declare -n ref="hello"
declare -a hello=([0]="world" [1]="me")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]