2

我有一个变量是否存在取决于我的输入,所以我做了一个 if :

if { [info exists $var1] } {
    puts "Here we are, Born to be kings, We're the princes of the universe ..."
}

但是当我启动我的脚本时,我得到了错误日志:

can't read "var1": no such variable
while executing
"info exists $var1"

有什么错误?

4

1 回答 1

7

采用if { [info exists var1] } {...

变量在调用之前info被替换,也不例外。所以传递变量的名称而不是它的值。

于 2012-08-29T13:43:26.797 回答