Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a variable which contains other variables that will change in Bash?

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)

like image 556
Snoop05 Avatar asked Dec 05 '25 03:12

Snoop05


1 Answers

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)"
like image 121
glenn jackman Avatar answered Dec 07 '25 18:12

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!