Forum Discussion
Using variables as the match expression on the switch command
I'm fairly certain the answer to this is no (though Tcl reference suggests it is allowed), but can the expression to match against on a switch command be defined as a variable.
switch [HTTP::uri] {
"$matchpage1" {
....
}
"$matchpage2" {
....
}
}
3 Replies
You can do it, but it's kind of awkward. The issue is the surrounding "{" and "}" around the comparison strings that's causing the strings to be treated as literals. If you remove the enclosing curly braces and end each line with a continuation character, it will work. Something like this
switch -- [HTTP::uri] \ "$matchpage1" { ... } \ "$matchpage2" { ... }Check out the wiki switch topic for an example (at the bottom)
https://devcentral.f5.com/wiki/iRules.switch.ashx
Hope this helps...
-Joe
- Doug_Jones_2417
Nimbostratus
Thank you, brilliant. And thank you for the explanation re the surrounding brackets. Doug.
No problem. If you think this answered your question, can you mark the question as a correct answer? Thanks!
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com