user2712491
user2712491

Reputation:

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__

Upvotes: 8

Views: 26362

Answers (1)

Aleks-Daniel Jakimenko-A.
Aleks-Daniel Jakimenko-A.

Reputation: 10653

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.

Upvotes: 9

Related Questions