我正在做这样的事情:
#!/usr/bin/expect -f
if {$out != ""} {
send_user $out
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.错误信息:
can't read "out": no such variable
while executing
"if {$out != ""} {
send_user $out
}"
(file "./test" line 3)
Run Code Online (Sandbox Code Playgroud)
Din*_*esh 12
你得到的错误是因为变量不存在out.
要检查变量的存在,请使用以下命令
if {[info exists out]} {
puts "variable does exist"
}
Run Code Online (Sandbox Code Playgroud)
info exists 如果变量存在则返回1,否则返回0.
如果存在变量,那么您可以使用您发布的代码.