Main shell loop implemented as a separate function called wshmain.