Skip to content

switch ​

Multi-way branching based on pattern matching.

Syntax ​

tcl
switch ?options? string ?pattern body ...? ?default body?

Parameters ​

  • options: Matching mode flags
    • -exact: Exact string matching (default)
    • -glob: Glob-style pattern matching
    • -regexp: Regular expression matching
  • string: Value to match against patterns
  • pattern: Pattern to match
  • body: Script to execute if pattern matches; use - for fall-through
  • default: Keyword for the fallback case

Examples ​

Basic exact matching ​

Output

Glob pattern matching ​

Output

Fall-through with dash ​

Output

Using list syntax ​

Output

See Also ​

  • if - Conditional execution
  • expr - Expression evaluation