How do I assign a value to variable that has a variable in its name?
var1="file"
var2_$var1="folder"
The code above gives me the error -bash: var2_file=folder: command not found
. I was curious to know how to assign to a variable with another variable in its name.
Version of Bash is "GNU bash, version 4.1.2"
With
bash
you can usedeclare
:How about using another variable to hold the dynamic name and use it for retrieving the value after setting?
Unfortunately, Bash doesn't allow
declare $new_var="123"
- that would have made this a little prettier.