Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想写这样的文件:
set fh [open $tmpFileName w] puts $fh "set a [create_object]" puts $fh "$a proc1_inside_a" puts $fh "$a proc2_inside_a" close $fh
但它会收到错误消息,因为a将在执行文件时创建变量tmpFileName。所以我得到这样的错误:
a
tmpFileName
can't read "a": no such variable
你能帮我解决这个问题吗?
您只需要使用不同的引用机制。双引号允许命令和变量替换。大括号将逐字保留其内容(禁止替换)
set fh [open $tmpFileName w] puts $fh {set a [create_object]} puts $fh {$a proc1_inside_a} puts $fh {$a proc2_inside_a} close $fh
可用文档: