bug-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: Léa Gris
Subject: Re: Issue declaring an array via a variable name
Date: Sun, 15 Aug 2021 11:57:44 +0200
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 15/08/2021 à 02:45, Hunter Wittenborn écrivait :
- declare -g "${variable}"=("world" "me")
- declare -g ${variable}=("world" "me")
- declare -g "hello"=("world" "me")

Invalid because the string "${variable}" cannot be assigned = the scalar ("world" "me")

If you want to dynamically compose the declare arguments, it either need to be only a string or only variable=value(s)

So these work because the argument is a string

declare -g "$variable=( \"world\" \"me\" )"
declare -g "$variable"'=( "world" "me" )'

Be cautious with dynamic declare statements, because it is as insecure as eval. It will execute statements contained in variables.

--
Léa Gris




reply via email to

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