I am trying to figure out how to call a variable variable and I am unable to get it to work. Let me first explain a little. I have a script that I want to run the same process on multiple spawn instances without having to define the same process over and over.
So my script is set to spawn a shell prompt and login to several devices. I then create a variable for each spawn_id and the prompt of the device that I login to.
I would like to do something like the following
set devices "L1 L2 L3"
foreach i $devices {
spawn $env(SHELL)
set $i\SHELL $spawn_Id
expect -re "\((\>|%|#|\\\$) $\)" { set prompt$i $expect_out(1,string) }
}
Then I need to call these again later on so
foreach i $devices {
set spawn_id $$i\Shell
The last line is what I just can't find any examples of how to do. The variables are set fine up above but I can't call the variable that contains the variable "$$i\Shell" for example.
I am not sure the syntax
I have tried:
$($i\Shell) **which gives me can't read "(L1Shell)": no such variable
$`$i\Shell` **Gives me "can not find channel named $`L1Shell`"
$ ** invalid command name "L1Shell"
${$i\Shell} ** can't read "$i\Shell": no such variable
Somehow I want to be able to call $L1Shell $L2Shell $L3Shell by by doing
set device "L1 L2 L3"
foreach i $device {
set spawn_id $$iShell ! This syntax for this double variable I cannot figure out. I lack the experience.
}