Search code examples
shellexpect

How to compare two ints in expect shell?


I want subtract a number in expect shell until it equals 0, then close this shell, such as :

#!/usr/bin/expect
set round [lindex $argv 0];
incr round -1
if round <= 0 close  // ??how to write this sentence?

Solution

  • Your last line would be:

    if {$round <= 0} exit
    

    BUT I think you actually want to decrement the counter repeatedly, for which you would need a loop:

    while {$round > 0} {
        incr round -1
    }