How to use switch or tcl statement?

I want to have a large list of options in my script. The user will give input that matches only one of these parameters. I want to have several different options for executing the same commands, but I can't get ORs to work. Below I think it should look, any ideas on how to make work a or b?

switch -glob -- $opt {
   "a" || "b" {
      puts "you selected a or b, probably not both"
   }
   default {
      puts "Your choice did not match anything"
   }
}
+5
source share
3 answers

You can use -as a body for the occasion to go to the next body, as described in Tcl Manual

"-", , ( "-", , ). .

, , , , opt :

switch -glob -- $opt {
   "*a*" -
   "*b*" {
      puts "you selected a or b, probably not both"
   }
   default {
      puts "Your choice did not match anything"
   }
}
+10

. : " glob ..."

+1

We are also working on this:

switch -regexp -- $opt {
   a|b {
      puts "you selected a or b, probably not both"
   }
   default {
      puts "Your choice did not match anything"
   }
}

Note: there are no spaces between "a | b"

0
source

All Articles