Change the first line from:
switch=$(ssh 192.16810.10.10 egrep somefile /tmp/tmpfile.txt)
To the following:
export switch=$(ssh 192.16810.10.10 egrep somefile /tmp/tmpfile.txt)
I've encountered a near identical problem many times before, or when when incrementing a variable. Where
variable=$variable+1 would append the text string
"++" to the end each time it looped instead of incrementing like it like it should.
let variable=$variable++ or
let variable=$variable+1 immediately fixed the issue. Using
export also worked if everything was set before the loop started.
I believe bash is doing something wrong when it stores that variable. Thus it makes the comparison act up, and using let/export does something different to store it. I was searching for an answer to the same question, except I was getting inconsistent results comparing numbers instead of strings. In any case, it can't hurt to try using export before the first statement.