Linux – Passing variables into ssh sessions (Session has to stay alive)

bashenvironment-variableslinuxssh

is it possible to start a ssh remote session and pass a variable to the remote host, which is usable in the opened session.

For Example:

Client:
testvar="this is my text"
Open ssh session (ssh user@remotehost) and pass $Testvar to the remote Session

Host:
Once the connection is opened I want to be able to use the passed variable to be able to read the variable to get the output "this is my text"

I need my console session to stay live, which doesnt work in usual ssh remote excecution because a command will be excecuted and the ssh session will be terminated right after. (as far as I know)

Thank you!

Best Answer

I think you can try this:

ssh user@host -t 'export var="value"; bash' 
Related Question