Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the value of second level variable in Bash?

Let's consider 2 variables in bash as following:

X = 8  
Y = X

If I want to print the value of X using the variable Y I could do echo ${!Y} and the value 8 will be printed

Now the question is, how can I change the value of X using the variable Y ?

like image 834
Debugger Avatar asked Jan 18 '23 21:01

Debugger


1 Answers

By using eval:

$ X=8
$ Y=X
$ echo ${!Y}
8
$ eval $Y=3
$ echo $X
3
like image 89
fge Avatar answered Jan 28 '23 16:01

fge