问题
I have written one TCL script but I have one problem when making a string variable as below:
set a 100
set b "this is variable[$a]"
I want b to be assign with b = "this is variable[100]" but I got the error:
invalid command name 100
Please help me to fix it :-(.
回答1:
You just need to escape it:
set a 100
set b "this is variable\[$a\]"
回答2:
Other possibilities (but escaping the brackets is better):
set b [format {this is variable[%d]} $a]
set b [subst -nocom -noback {this is variable[$a]}]
Documentation: set, format, subst
来源:https://stackoverflow.com/questions/39974070/how-i-add-bracket-in-string-variable-in-tcl-file