Is there a way to change the contents of a string with variable expansion and have the contents update if the variable does?
Like so:
var1=0 # set var1
var2="$var1" # set var2 to var1
var1=1 # set var1 to something else and have var2 change as well?
I know this example will not work but it is just to show you guys what I'm trying to do.
Is there any way at all to accomplish this without always setting var1 before var2?
Thanks in advance
EDIT: Also, is it possible to do this with a variable that hasn't been set before the first one? Like so:
var2=$var1
var1=10
echo $var2
I want the output to be 10 but since var1 is not set when assigned to var2, the var2 will also be empty. Help