Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch cmd - matching non-case sensitive

Status
Not open for further replies.

LilTCLer

Programmer
Nov 27, 2007
37
US
I want to match a string regardless of whether it is upper or lower case and I can't figure out how to do this. This seems pretty easy, but yet it crashes at runtime. Here is a snippit of my switch statement:

switch -nocase -- $termserver {
a { set termServerIP "172.23.129.10" }
b { set termServerIP "172.23.129.11" }
}

I've also tried:

switch -regexp -nocase -- $termserver {
a { set termServerIP "172.23.129.10" }
b { set termServerIP "172.23.129.11" }
}

Here is the error:

bad option "-nocase": should be -exact, -glob, -regexp, or --
while executing

Any ideas?
 
Awesome, thanks - I'll give that a go.

Also, what is the best way to match A or 1?

For example,

switch -regexp -- $termserver {
a {
set termServerIP "172.23.129.10"
}
1 {
set termServerIP "172.23.129.10"
}
}

Since these are the same actions, I'd like to combine what is being matched like so:

switch -regexp -- $termserver {
(a or 1) {
set termServerIP "172.23.129.10"
}
}
Is there a way to do this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top