in reply to problem in loop break

This is no loop, this is recursion. And at some point you're gonna get the dreaded "deep recursion" warning. Your sub shapcs should accept 2 and 2 things only: an already connected ssh handle and the command.