How would I get the switch statement to math the closing bracket? I tried both "[][]" and "[[\]]"
set x "]"
switch -glob $x {
"[[\]]" {
puts "MATCH ]"
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you want to match
]as part of a group of characters inswitch, you’ve only got a few options:Use
-regexpmatching instead of-glob. It’s more complex, requires a different pattern, but it’s also definitely more flexible (especially when it comes to things like this).Use multiple clauses with body sharing:
What you can’t do is put a
]in a glob match set except as a non-initial part of a range (the glob matcher is pretty dumb, but fast). There isn’t any suitable range that would match exactly what you’re after here, so a single glob won’t work.