Store output of a script run over ssh in a variable

I’m trying to capture output of a script (resides on a remote server) run over SSH into a variable, below is my code:

ssh username@hostname << EOF
variable=`./script_on_remote_server.sh`
echo $variable
EOF

When i run the above script, nothing gets stored in the variable and echo of that variable returns nothing.

What am I doing wrong?


Source: shell

Leave a Reply