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