I have a string that contains a use of some variable, and I'd like to substitute that variable's value into the string. Right now the best I have is
#!/bin/bash
foo='$name; echo bar'
name="The    name"
expanded="$(eval echo "$foo")"
echo "$expanded"
Which has some obvious defects: it prints
The name
bar
while I'd like it to print
The    name; echo bar