Question

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.

Was it helpful?

Solution

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 and expr. incr may be used when you are adding an integer value to another integer. It is very fast for that operation. For example:

set value 1
incr value

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 in incr value -1). If you need something more elaborate, you should use expr:

set value 1
set value [expr {$value + 1}]

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.

OTHER TIPS

I would start here at the official website.

Ahh, ok, I figured it out:

set count [expr $count+1]

This adds 1 to the count variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top