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

时间:2016-10-11 09:19:57

标签: tcl

我已经编写了一个TCL脚本,但在制作字符串变量时我遇到了一个问题:

set a 100
set b "this is variable[$a]"

我想要b分配b =" this is variable[100]"但我得到了错误:

invalid command name 100

请帮我解决一下: - (。

2 个答案:

答案 0 :(得分:2)

你只需要逃避它:

set a 100
set b "this is variable\[$a\]"

答案 1 :(得分:0)

其他可能性(但转出括号更好):

set b [format {this is variable[%d]} $a]
set b [subst -nocom -noback {this is variable[$a]}]

文档: setformatsubst