Reputation: 55
var1=0
var=$var1
(Some conditions that may change $var1)
var1=1
echo $var
I need to have 1
as output of echo $var
. In other words, I need to get a new value if the variable1 contained in variable if it change.
Are there some special options or quotes that will allow me to do that?
EDIT:
FILE=ArchLinuxARM-$DATE-$TARGET.img
DATE=2015.10
TARGET=rpi-2
echo ${!FILE}
Will echo nothing. (It should echo ArchLinuxARM-2015.10-rpi-2.img
)
Upvotes: 3
Views: 298
Reputation: 246774
For your specific question, you'd be better served with a function:
filename() { echo "ArchLinuxARM-$DATE-$TARGET.img"; }
DATE=2015.10
TARGET=rpi-2
echo "$(filename)"
Upvotes: 3
Reputation: 246774
In bash version 4.3, you can create reference variables:
$ echo $BASH_VERSION
4.3.42(1)-release
$ declare -n var=var1
$ var1=0; echo $var
0
$ var1=1; echo $var
1
Upvotes: 0