根据我的输入,我有一个存在或不存在的变量,所以我做了一个if:
if { [info exists $var1] } {
puts "Here we are, Born to be kings, We're the princes of the universe ..."
}
Run Code Online (Sandbox Code Playgroud)
但是当我启动我的脚本时,我收到了错误日志:
can't read "var1": no such variable
while executing
"info exists $var1"
Run Code Online (Sandbox Code Playgroud)
怎么了?
使用 if { [info exists var1] } {...
在调用之前替换变量,并且info也不例外.所以传递变量的名称而不是它的值.