Is it possible to build variable names from other variables in bash? [duplicate]

Yes, but don’t do that. Use an array instead.

If you still insist on doing it that way…

$ foo1=123
$ bar=foo1
$ echo "${!bar}"
123

Leave a Comment