This is a variation of the question here: How have both local and remote variable inside an SSH command
How do I get the "ssh-variable" B to my local computer?
A=3
ssh host@name "echo $A; B=5; echo $A; echo \$B;"
echo $A
echo $B
echo \$B
returns 3, NOTHING, $B
How can I locally access a value for B?
some explanations based on comments: I am using a bash script to access a remote host to modify some things there, amongst other things create a workspace there. The location of this workspace is what I want to store in a variable and save for later use.
Basically, I have a function to go to the remote host and make the workspace and then another function to use the path to that workspace to do other things there.
I was hoping for a lightweight, slim solution that can be integrated and easily read in a command similar to this:
ssh host@name "ws_allocate myworkspace; workspace=ws_find myworkspace;"
and then locally use $workspace. This is part of a larger bash script, that should be easy to understand for non-expert bash users (like myself)...
Turns out this is a duplicate of bash—Better way to store variable between runs?
ssh, why don't you just define it locally to begin with?