Я столкнулся с той же проблемой и, посоветовавшись с man ssh, выяснил:
# Problem: if you copy & paste those two lines together into a shell,
# then the second command is not executed.
# But if you run each line on its own, it will work
srcdirs=$(ssh myserver "ls -1 /home")
echo "$srcdirs" # command is also not recorded by history
# Solution: Redirect stdin from /dev/null
srcdirs=$(ssh -n myserver "ls -1 /home")
echo "$srcdirs"
Надеюсь, это решит вашу проблему...