I would like to set a variable to the output of a ssh command in zsh. The ssh command itself connects to a first server, then ssh again from this server to a second server where I want to execute my command.
Here is the command (works fine when typed in the shell) :
ssh -t host1 "ssh -t host2 "uname -a""
I have an ssh key setup for host1, so the connection doesn't ask for a password. I don't have one for the subsequent connection between host1 and host2, so I have to type the password.
Now, I would like to save the content of
uname in a variable, to be used in my zsh script. I naively tried :
a=$(ssh -t host1 "ssh -t host2 "uname -a"")
but it seems to hang forever, somehow the interactive password login prompt is not redirected to me. If I try a
echo $a afterwards I got a
user@host2's password:' to confirm it
My guess is that something went wrong in the way zsh handles quotes and double quotes, but I could not figure out what. I've tried many variations, without success.