Search code examples
tclexpect

How to create a "loop" statement within an {expect} script?


Assumption is, this is the script

#!/usr/bin/expect
set a "__test__"

i would like to create a loop inside this script so it can print the value for

 $a

with the a number infront of it based on the loop.

so if i wanted it to loop 3 times.. end product would become:

 1:__test__
 2:__test__
 3:__test__

Solution

  • You can use for

    #!/usr/bin/expect
    set a "__test__"
    for {set x 0} {$x<3} {incr x} {
       puts "$x:$a"
    }
    

    See more info in tcl commands because expect is an extension to tcl language.