<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def toggle_shells(command, enable):
 """Enable or disable the specified shells. If the command would have no effect, it changes all other shells to the inverse enable value."""

    selection = list(selected_shells(command))
    if command and command != '*' and selection:
        for i in selection:
            if i.state != remote_dispatcher.STATE_DEAD and i.enabled != enable:
                break
        else:
            toggle_shells('*', not enable)

    for i in selection:
        if i.state != remote_dispatcher.STATE_DEAD:
            i.set_enabled(enable)