TCL在字符串中设置特殊字符

cod*_*rot 1 tcl

我想在TCL中将以下错误消息设置为变量,并与来自网络交换机的错误消息进行比较,绕过特殊字符

使用[slot/port]或["portname"]或[slot/*]或[*].

我试过这种方式

set x "Use \[slot/port] or \["portname"] or \[slot/\*] or \[\*]."
Run Code Online (Sandbox Code Playgroud)

但我在运行脚本时收到以下消息:

执行后关闭引用后的额外字符

请帮忙.谢谢!

gle*_*man 11

如果使用双引号,则还必须转义"内部"引号:

set x "Use \[slot/port] or \[\"portname\"] or \[slot/*] or \[*]."
Run Code Online (Sandbox Code Playgroud)

或使用大括号,避免完全逃脱

set x {Use [slot/port] or ["portname"] or [slot/*] or [*].}
Run Code Online (Sandbox Code Playgroud)

请参阅Tcl的12个语法规则,数字4和6