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: Alex fxmbsw7 Ratchev
Subject: Re: Issue declaring an array via a variable name
Date: Mon, 16 Aug 2021 16:10:31 +0200

i dunno but, i had many testings many times
the stable wanted is to enclose the per arg definition in quotes, not like
"var"="var"
the right dash options is also useful

test=( a b ) t=var
declare -ga "$t=( ${test@Q} )"
the same style i found secure and data preserving such alike:
"list=( $( ls -Ac --quoting-style=shell-escape ) )"

i didnt really test i typed in my phone, but in recent bashes such worked
fine

On Mon, Aug 16, 2021, 15:57 Chet Ramey <chet.ramey@case.edu> wrote:

> On 8/14/21 5:53 PM, Hunter Wittenborn wrote:
> > Hi!
> >
> >
> >
> > I wasn't sure if this was a bug (though it seemed quite likely for me),
> so I went ahead and decided to post the issue here before resorting over to
> the bug mailing list.
> >
> >
> >
> > Anyway - For some reason, the following code keeps failing whenever I
> run it:
> >
> >
> >
> > "
> >
> > variable="hello"
> >
> >
> >
> > declare -g "${variable}"=("world" "me")
>
> It's a syntax error. There is an unquoted operator (`(') where the grammar
> does not allow it.
>
> `declare' does allow compound array assignment statements as arguments, and
> the parser accommodates this as long as two conditions hold: the parser can
> detect that the first word of a simple command is `declare' and the
> argument is a valid assignment statement. In this case, the second fails,
> since `"${variable}"' is not a valid shell identifier. That renders the
> argument not a valid assignment statement.
>
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>
>


reply via email to

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