如何创建“循环"{expect} 脚本中的语句? [英] How to create a "loop" statement within an {expect} script?
本文介绍了如何创建“循环"{expect} 脚本中的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设是,这是脚本
#!/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.
所以如果我想让它循环 3 次.. 最终产品将变成:
so if i wanted it to loop 3 times.. end product would become:
1:__test__
2:__test__
3:__test__
推荐答案
您可以使用 为
#!/usr/bin/expect
set a "__test__"
for {set x 0} {$x<3} {incr x} {
puts "$x:$a"
}
在 tcl 命令 中查看更多信息,因为 expect
是 tcl
语言的扩展.
See more info in tcl commands because expect
is an extension to tcl
language.
这篇关于如何创建“循环"{expect} 脚本中的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文