期待补充
我最近一直在玩expect,我一生都无法弄清楚如何对我传入的变量执行简单的加法。有人知道如何做到这一点吗? 另外,有没有关于 Expect 的不错的在线参考? 我尝试过谷歌搜索,但结果非常有限。
I have been playing around in expect recently and I for the life of me can't figure out how to perform a simple addition on a variable I passed in. Anyone know how to do this? Also, is there a decent online reference for Expect? I have tried googling with very limited results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于 Expect 需要记住的一点是,它实际上只是 Tcl 的扩展,因此如果您正在寻求编写 Expect 脚本的帮助,并且您的问题与 Expect 特定命令之一无关,您应该尝试查找 Tcl 参考资料。 一个好的起点是http://www.tcl.tk,以及http://wiki.tcl.tk。
有两种方法可以完成您想要做的事情:
incr
和expr
。 当您将一个整数值添加到另一个整数时,可以使用incr
。 该操作的速度非常快。 例如:但是,
incr
不适用于非整数值,并且除了加法之外不能执行任何操作(如果对增量取反,则不能执行减法,如incr value -1< /代码>)。 如果您需要更详细的内容,您应该使用
expr
:注意表达式周围使用大括号! 虽然它们通常不是正确操作所必需的,但它们可以提高性能。 如果您正在进行许多算术运算,在表达式周围使用大括号将显着提高脚本的性能。 有关详细信息,请参阅http://wiki.tcl.tk/10225。 在使用
expr
时,您应该养成始终支撑表达式的习惯。您可以在 http://wiki.tcl.tk/201 中找到多个 Expect 资源的链接。
The thing to remember about Expect is that it's really just an extension to Tcl, so if you are looking for help on writing Expect scripts and your question is not related to one of the Expect specific commands, you should try looking in the Tcl references. A good starting place is http://www.tcl.tk, as well as http://wiki.tcl.tk.
There are two ways to do what you're trying to do:
incr
andexpr
.incr
may be used when you are adding an integer value to another integer. It is very fast for that operation. For example:However,
incr
does not work with non-integer values, and it can't do anything but addition (or subtraction if you negate the increment, as inincr value -1
). If you need something more elaborate, you should useexpr
:Note the use of curly braces around the expression! Although they are not required for correct operation in general, they improve performance. If you are doing many arithmetic operations, using braces around the expressions will significantly improve the performance of your script. For more information, see http://wiki.tcl.tk/10225. You should get in the habit of always bracing your expressions when using
expr
.You can find links to several Expect resources at http://wiki.tcl.tk/201.
啊,好吧,我想出来了:
set count [expr $count+1]
这会给 count 变量加 1。
Ahh, ok, I figured it out:
set count [expr $count+1]
This adds 1 to the count variable.
我将从官方网站开始。
I would start here at the official website.