user117974
user117974

Reputation: 421

bash referencing a variable inside another one

I am trying to reference a variable within another one but its not working for me

$ bond0_enable='yes'
$ echo $bond0_enable
yes
$ i=0
$ echo $bond$i_enable

I want to reference the whole variable to read $i, how is this done please?

Upvotes: 0

Views: 48

Answers (1)

fedorqui
fedorqui

Reputation: 289645

Like this, for example:

$ bond0_enable='yes'
$ i=0
$ d=bond${i}_enable
$ echo ${!d}           <----- key point, ${!name} makes it
yes

Upvotes: 2

Related Questions