Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Jun 18, 2012

one question in variable

in the syntax ,we normally use :

 

 

if { $cjj == 1} {

 

xxxx

 

}

 

 

I have a question here

 

 

sometimes I forget to define this variable cjj,is there any method I can use to make it work in this way:

 

evulate wether there is a varable cjj,if not define one

 

 

such as :

 

if $cjj exist ,else set cjj x

 

 

thanks in advance

 

4 Replies

  • Richard__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    You can use Catch. if there is a error the catch command will catch the error and allow you to work around it with out aborting the iRule

     

     

    https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/137/iRules-101--07--Catch.aspx

     

  • yes,catch seems a good command ,but another question raise,

     

    if I want to check whether one variable exists catch {command},which command I should use in the curly braces?
  • Or you can use [info exists variable]:

     

     

    if { [info exists cjj] and $cjj == 1} {

     

    xxxx

     

    }

     

     

    http://www.tcl.tk/man/tcl8.4/TclCmd/info.htm

     

     

    Aaron