concatenate values to create variable name

search tag # rextended dynamic variables


This:

:global $wan1 1;
:put ("wanSta" . $wan1);
:set ("wanStatus" . $wanIndex) 10

give two errors:
first one because the $ on front of wan1 is forbiden when declaring a global or local variable (I use 6.47.10)
second because the wan1 is undefined on second line for the reason writed before
third on last line you use another name wanStatus

The correct syntax is:

:global wan1 1
:put "wanSta$wan1"
:set wanSta1 10

but obviously do not create or set the variable wanSta1


Short answer:
You can not refer to variables using a result from one operation, but you can use my method:
:global variablename “test”

Create a global variable using the name inside “variablename” and set the value (or update the value if is already defined)

[:parse “:global $variablename "REX1"”]

after “parse” the variable exist and can be displayed

:put $test

Set a value of variable with name defined inside “variablename” (or simply apply previous “parse” command)

[:parse “global $variablename;:set $variablename "REX2"”]
:put $test

For read the value, of a variable with name defined inside “variablename”, and put it inside another global or local declared variable:

:global testx [[:parse “:global $variablename; :return $$variablename”]]
:put $testx

For read the value, of a variable with name defined inside “variablename”, simply for put the value on terminal:

:put [[:parse “:global $variablename; :return $$variablename”]]

Or on alternative way: (but this throw an error if the variable not previously created)

:put [/system script environment get $variablename value]
After that the OP script must be:

:global wan1 1
:global variablename "wanSta$wan1"
[:parse ":global $variablename \"10\""]
:put [[:parse ":global $variablename; :return \$$variablename"]]

EDIT: Edited to reflect better OP script