0

Hi So I have saved a bunch of variables:

fxp0_21_mac = 0A:AA:FF:C1:A1:EE
fxp0_22_mac = 0A:AA:FF:C1:A2:EE
fxp0_23_mac = 0A:AA:FF:C1:B1:EE
fxp0_24_mac = 0A:AA:FF:C1:B2:EE
fxp0_25_mac = 0A:AA:FF:C1:C1:EE
fxp0_26_mac = 0A:AA:FF:C1:C2:EE
fxp0_27_mac = 0A:AA:FF:C1:D1:EE
fxp0_28_mac = 0A:AA:FF:C1:D2:EE``

I am trying to loop for each of those variables by replacing the number 21, for instance in the variable fxp0_21_mac into a different number for example 22

The numbers 21 to 28 are going to be loop in sequence:

for ((CN=21;CN<=28;CN++)); do
   
    (for example): x=$(echo fxp0_$CN_mac) 
    echo $x
    #print 0A:AA:FF:C1:A2:EE

done

However, I cannot get to print variable itself when changing the middle number.

my expected output:

echo $x
#0A:AA:FF:C1:A2:EE

my output:

echo $x
#fxp0_22_mac

Is there a way to change or replace a variable character and print the variable result which in this case would be a MAC ADDRESS?

nickcrv06
  • 127
  • 11
  • It's not clear to me what you mean. Do you want to rename a variable? BTW, why do you use 8 individual variables instead of a single associative array, where the key is something like `21` or `22`? – user1934428 May 02 '22 at 09:04
  • Dynamic variables names was the solution! – nickcrv06 May 02 '22 at 09:23

0 Answers0