Create local and remote variables in bash SSH

Home > Search

Let's say you have two Linux servers, and, and you want to create a variable on server1, then SSH into server2, create a variable on server2, and be able to use both variables. In this example, the "a" variable is created on server1, and the "b" variable is created on server2, and echo properly displays the value of both "a" and "b" in the console.

~]$ a="Hello"; ssh root@server2 "b="World"; echo $a; echo \$b;"


I do not believe there is a way with Bash to create a variable in the SSH session and then use the variable by the local host.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.