Bash (Scripting) - local and remote variables with SSH
by
Jeremy Canfield |
Updated: March 08 2020
| Bash (Scripting) articles
Let's say you have two Linux servers, server1.example.com and server2.example.com, 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;"
Hello
World
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.
Did you find this article helpful?
If so, consider buying me a coffee over at