case(3tcl)
π case(3tcl) β Tcl Built-In Commands π
okay bestie, gather round, because we're looking at a Tcl Built-In Commands page and this one is... a little vintage π΅β¨. It's case, it's from the Tcl era of 7.0, and it's giving "my grandma's flip phone that still works perfectly". Let's get into it π«Ά
β¨ NAME β¨
case β pick one script to run based on whatever value you handed it π
πΈ SYNOPSIS πΈ
case string ?in? patList body ?patList body ...?
case string ?in? {patList body ?patList body ...?}
π DESCRIPTION π
π¨ Not me being the bearer of bad news π¨ butcaseis obsolete, bestie. It's only hanging around for backward compatibility. At some point in the future it may be removed entirely. So like... use theswitchcommand instead, fr fr. π
okay so here's how the actual matching works π
case matches string against each of the patList arguments, in order. Each patList argument is a list of one or more patterns. If any of these patterns matches string, then case evaluates the following body argument by passing it recursively to the Tcl interpreter, and returns the result of that evaluation. β¨
Each patList argument consists of a single pattern or a list of patterns. Each pattern may contain any of the wild-cards described under string match β yes, the whole wildcard buffet, help yourself π.
If a patList argument is default, then the corresponding body gets evaluated when no patList matches string. And if no patList argument matches string and no default is given? Then case just returns an empty string. Nothing. Silence. The void. π
π¦ The Two Syntaxes π¦
Two syntaxes are provided for the patList and body arguments, and honestly they each have their own main character energy:
- The separate-arguments form β uses a separate argument for each of the patterns and commands. This form is convenient if substitutions are desired on some of the patterns or commands. Lowkey the flexible one πββοΈ
- The one-big-list form β places all of the patterns and commands together into a single argument. That argument must have proper list structure, with the elements of the list being the patterns and commands. This form makes it easy to construct multi-line
casecommands, since the braces around the whole list make it unnecessary to include a backslash at the end of each line. (No more\at every line break, we love a convenience era π)
β οΈ but wait β since the patList arguments are in braces in the second form, no command or variable substitutions are performed on them. This makes the behavior of the second form different than the first form in some cases. So pick wisely, bestie, they are NOT the same girl π
π₯ SEE ALSO π₯
switch(3tcl)β the upgrade, the glow-up, the one you should actually be using π
π KEYWORDS π
case, match, regular expression
and that's the whole page, no notes π this was Tcl, version 7.0, filed under case(3tcl) β shoutout to the Tcl Built-In Commands manual for keeping this relic alive. slay, stay obsolete, bye bestie πβ¨π«Ά
π¦ where this page comes from
- debian bookworm: tcl8.6-doc 8.6.13+dfsg-2
- debian trixie: tcl8.6-doc 8.6.16+dfsg-1
- ubuntu jammy: tcl8.6-doc 8.6.12+dfsg-1build1
- ubuntu noble: tcl8.6-doc 8.6.14+dfsg-1build1
- ubuntu questing: tcl8.6-doc 8.6.17+dfsg-1
- ubuntu resolute: tcl8.6-doc 8.6.17+dfsg-1build1
- ubuntu stonking: tcl8.6-doc 8.6.18+dfsg-1
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms