How can I ssh into a server and set an environment variable for the remote shell session? Ideally I'd like to control the name and value of the variable from the origin host.

link|improve this question
feedback

4 Answers

SSH into the machine and then run export SHELLVAR=value. Put that into the .bashrc for the account if you want to make it permanent.

link|improve this answer
or /etc/profile for a global export. – Dave Rickman Aug 18 '09 at 3:44
feedback

Use "SendEnv" configuration variable of ssh. see man ssh_config for more information.

link|improve this answer
Interesting. Never knew about that configuration variable. Nice to learn something new! – fpmurphy Aug 18 '09 at 14:03
feedback

If you're running a single-shot command on the remote side, something like this may work for you:

ssh user@remote "MYVAR=blah the_command -with args"

You can string multiple commands together as well:

ssh user@remote "export MYVAR=blah; one_command -with args && command2; command3"
link|improve this answer
feedback

Depends of shell used on remote host. Check this link:
Environment Variables

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.