简体   繁体   中英

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.

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

send_user "[set IO$i] value is: $XXXXXX ?

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: $XXXXXX ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM