TCL-匹配球形格式的右括号

Bar*_*uch 2 glob tcl

我将如何得出switch算术结束语的陈述?我都尝试"[][]""[[\]]"

set x "]"

switch -glob $x {
    "[[\]]" {
        puts "MATCH ]"
    }
}
Run Code Online (Sandbox Code Playgroud)

Nox*_*oxx 5

您可以使用:

set x "]";
switch -glob $x {
    \] {
        puts "MATCH ]"
    }
}
Run Code Online (Sandbox Code Playgroud)

或比括号更匹配:

set x "foo]bar";
switch -glob $x {
    *\]* {
        puts "MATCH ]"
    }
}
Run Code Online (Sandbox Code Playgroud)