variable within a variable from file

script below sets variable "var". Then sets "var2" (which contains "var" whithin it, see test.config file) from config file.

test.sh
----------------------------

#!/bin/sh
var="varvalue"
while read line
do
        var2=${line[0]}
done <./test.config
 
echo "var value is: $var"
echo "String from file: $var2"

----------------------------

test.config (the line contains a variable)

----------------------------

String is variable ${var}

----------------------------

but output doesn't recognise $var inside $var2 as a variable, even though it is set:
----------------------------

var value is: varvalue
String from file: String is variable ${var}

----------------------------

any solution to this? basically i need to read some lines from a file recognising the variables instead of taking them as simple strings.

any help really appreciated. thanks.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Var2 would have to re-valuated, as in:

Which will result in:

var value is: varvalue
String from file: String is variable varvalue

Warning
Please be aware that anything in your inputfile is evaluated, including:

Remove all files: $(rm -rf /)
String is variable ${var}