Forum Discussion

boneyard's avatar
Apr 25, 2012

looking for nicer way to have variable in the middle of string

i want to create a string where the variable part is in the middle, iRule / TCL doesn't totally get this.

 

 

the line below causes the system to assume the variable is $variable_fixedpart2, not just $variable

 

 

set name "fixedpart1_$variable_fixedpart2"

 

 

this works:

 

 

set name "fixedpart1_$variable"

 

append name "_fixedpart2"

 

 

but is there a nicer way, in one line for example?

 

  • Sure, you can use curly braces to escape the variable name:

     

     

    set name "fixedpart1_${variable}_fixedpart2"

     

     

    Aaron
  • thanks, works as a charm.

     

     

    i have to get used to curly braces for things like this, im using to using dots and "" for such things.