[clue] bash/using variables in variable names

marcus hall marcus at tuells.org
Fri Jun 21 19:26:54 MDT 2013


On Fri, Jun 21, 2013 at 03:05:39PM -0600, Mike Bean wrote:
> OK, I am just thoroughly writer's blocked, probably missing something
> obvious; but who knows.  Anyway, here's my question
> 
> # node=somenode
> # echo $node
> somenode
> # somenodeVar=5  * // if this works*
> # echo $somenodeVar
> 5
> # $node"Var"=5 *// why doesn't this work?*
> bash: somenodeVar=5: command not found

It seems that the shell parses variable assignments before variable
substitutions..  You can cause the shell to re-scan the line with
"eval":

# node=somenode
# eval ${node}Var=5
# echo $somenodeVar
5

marcus hall
marcus at tuells.org


More information about the clue mailing list