Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

OR condition inside IF statement

Hi

How can I check against two condition in the same if statement?

if { [ $cdomain ends_with ".com" ] || [ $cdomain ends_with ".dk" ] }{

This does not work 


thanx for help
bb
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

if { $cdomain ends_with ".com" or ".dk" }



if { $cdomain ends_with ".com" or $cdomain ends_with ".dk" }


I imagine the first one shoud work. If it doesn't, try the second one. You could always use a data group and class match a list of suffixes too.
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
This one should work:

if { $cdomain ends_with ".com" or $cdomain ends_with ".dk" }

You could also use a switch statement for this:


switch -glob $cdomain {
   "*.dk" -
   "*.com" {
      # matched .dk or .com
   }
   default {
      # No match
   }
}


Aaron
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Hi all

With this it works:

if { $cdomain ends_with ".com" or $cdomain ends_with ".dk" }


I did not test the switch but I'm sure it will work as well.


Many thanx for your help
andy
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
I usually us something like this:

if { ( $cdomain ends_with ".com" ) or ( $cdomain ends_with ".dk" ) } {
.... stuff
}

I recall having issues without the parens wrapping the blocks.
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
if { ( $cdomain ends_with ".com" ) or ( $cdomain ends_with ".dk" ) } { 
.... stuff 
} 

This works. Thanks :)

0