nia
nia

Reputation: 11

Variable expansion in expect script

Hope someone can help with this variable expansion inside expect script. I assign values to variables in a loop like Ex:

for {set i 1} {$i<=10} {incr i 1} {
 set IO$i [expr {$i + 1}]
}

I can get the variable values one by one by ex:

send_user "IO1 value is: $IO1"
send_user "IO2 value is: $IO2"
...

Is there a way that I can get the variable values inside the for loop, something like:

send_user "IO$i value is: $XXXXXX ?

Thank you.

Upvotes: 1

Views: 325

Answers (1)

glenn jackman
glenn jackman

Reputation: 246774

You can use the set command to get values as well as set them

send_user "IO$i value is: [set IO$i]"
# ........................^^^^^^^^^^

But it will be more convenient to use an array instead of a dynamically created variable

for {set i 1} {$i<=10} {incr i 1} {
 set IO($i) [expr {$i + 1}]
}
send_user "IO($i) value is: $IO($i)"

Upvotes: 1

Related Questions