Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do-while in Expect script

Tags:

expect

I wrote the below code and try to execute it. But i face the "invalid command name "do" while executing do {"

code:

#!/usr/bin/expect
set val 0;
set input 5;

do {
    puts "\nval = $val"
    set input [expr $input-1];
    set val [expr $val+1];
} while {input}

Please let me know to fix this issue. Does do-while exist in Expect script?

like image 351
Tamin Avatar asked May 29 '26 02:05

Tamin


1 Answers

The short answer is no.

The slightly longer answer is:

while true {
    puts "\nval = $val"
    incr val
    if {[incr input -1] == 0} break
}

The full discussion can be found on the Tcl wiki.

like image 168
glenn jackman Avatar answered Jun 01 '26 16:06

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!