Tcl 如何检查expect脚本中是否设置了变量?
我正在做这样的事情:Tcl 如何检查expect脚本中是否设置了变量?,tcl,expect,Tcl,Expect,我正在做这样的事情: #!/usr/bin/expect -f if {$out != ""} { send_user $out } 但它不起作用。错误消息: can't read "out": no such variable while executing "if {$out != ""} { send_user $out }" (file "./test" line 3) 您得到的错误是因为变量out不存在 要检查变量是否存在,请使用以下命令 if {[info
#!/usr/bin/expect -f
if {$out != ""} {
send_user $out
}
但它不起作用。错误消息:
can't read "out": no such variable
while executing
"if {$out != ""} {
send_user $out
}"
(file "./test" line 3)
您得到的错误是因为变量
out
不存在
要检查变量是否存在,请使用以下命令
if {[info exists out]} {
puts "variable does exist"
}
info exists
如果变量存在,则返回1,否则返回0
如果变量存在,那么您可以使用您发布的代码。我想您的意思是变量确实存在,而不是变量不存在:-)