Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm sort of confused of login shells and interactive shells.

If I run

ssh my_remote_server 'echo $HOME'

I can get


But when I run

ssh my_remote_server 'echo $ANOTHER_VAR'

I got a blank line.

export ANOTHER_VAR=$HOME/tr is set in both ~/.bashrc and ~/.profile on my_remote_server. So the question is, where should I set this variable? my_remote_server runs Ubuntu 12.04 btw.

share|improve this question
Do you mean it is exported in your local .bashrc or the one on the server you are connecting to? – terdon Jul 30 '13 at 14:55
@terdon on the server I'm connecting to – sean hawk Jul 30 '13 at 14:57
Hang on, are you setting it with the dollar sign? I mean do you have $ANOTHER_VAR=$HOME/tr in your .bashrc or ANOTHER_VAR=$HOME/tr? – terdon Jul 30 '13 at 15:03
@terdon sorry another typo :) – sean hawk Jul 30 '13 at 15:45

Note that variables are expanded in double quotes by the shell. It means the local value of the variable is printed. To get the remote variable, you have to use single quotes or backslash the dollar sign:

ssh remote_server 'echo $ANOTHER_VAR'
share|improve this answer
question updated, thanks! – sean hawk Jul 29 '13 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .