Forum Discussion
How can I have [variables] evaluated in a string?
Hi Adharkrader,
TCL can substitute any [command] or $variables on the fly, by just using...
log local0. "Var1 = $variable1 , Var2 = $variable2 , Request Host = [HTTP::host] , Request URI = [HTTP::uri]"
The use of [eval] is just required if the substituted string have to spann multiple command options, or if the command itself isn't subtitution aware...
set headers "\"Server\" \"MyWebserver\" \"X-Powered-By\" \"MyWebserver\""
eval "HTTP::response 200 content \"Hello World\" noserver $headers"
... would result into...
HTTP::response 200 content "Hello World" noserver "Server" "MyWebserver" "X-Powered-By" "MyWebserver"
... or ...
eval "unset -nocomplain [info vars temp_*]"
... may result into...
unset -nocomplain temp_1 temp_2 temp_3
... or ...
eval "set myvar_[IP::client_addr] \"somevalue\""
... may result into...
set myvar_192.168.0.1 "somevalue"
Note: Keep an eye on your performance when using [eval]. Most of the [eval] usecases are not byte-code aware and do therefore have a very impressive overhead!
Update: Added a third example showing a [command] that isn't substitution aware.
Cheers, Kai
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
