Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a variable is set in expect script?

Tags:

expect

tcl

I am doing something like this:

#!/usr/bin/expect -f

if {$out != ""} {
  send_user $out
}

But it doesn't work. Error message:

can't read "out": no such variable
    while executing
"if {$out != ""} {
send_user $out
}"
    (file "./test" line 3)
like image 563
Jahid Avatar asked Jan 15 '16 14:01

Jahid


1 Answers

The error you got is because of non-existence of the variable out.

To check variable's existence, use the following

if {[info exists out]} {
    puts "variable does exist"
}

info exists returns 1 if variable exist, else 0.

If variable exists, then you can use the code what you posted.

like image 89
Dinesh Avatar answered Sep 28 '22 05:09

Dinesh