如何在TCL文件的字符串变量中添加括号

如何在TCL文件的字符串变量中添加括号,tcl,Tcl,我已经编写了一个TCL脚本,但在创建字符串变量时有一个问题,如下所示: set a 100 set b "this is variable[$a]" 我想用b=“这是变量[100]”分配b,但我得到了错误: invalid command name 100 无效的命令名100 请帮我修好它:-(。你只需要逃出它: set a 100 set b "this is variable\[$a\]" 其他可能性(但最好避开括号): 文件: , , 请参见,特别是规则#7从技术上讲,我们只需要避开开

我已经编写了一个TCL脚本,但在创建字符串变量时有一个问题,如下所示:

set a 100
set b "this is variable[$a]"
我想用b=“
这是变量[100]
”分配b,但我得到了错误:

invalid command name 100 无效的命令名100
请帮我修好它:-(。

你只需要逃出它:

set a 100
set b "this is variable\[$a\]"
其他可能性(但最好避开括号):

文件: , ,

请参见,特别是规则#7从技术上讲,我们只需要避开开头的括号。非常感谢。我的问题是我使用的工具与TCL相同,但它不接受[和]字符串“[]”。看起来你对正在发生的事情理解错误。不是TCL不接受“[]”。问题是“[某些东西]”在Tcl中,表示您希望运行函数/proc/command
something
,然后将其插入字符串中。因此,要阻止Tcl认为您想要执行
something
,您需要告诉它,
[
并不表示您想要调用函数/command/proc。非常感谢。我使用set b[format]对其进行了修复{这是变量[%d]}$a]。
set b [format {this is variable[%d]} $a]
set b [subst -nocom -noback {this is variable[$a]}]