0

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

If I run

ssh my_remote_server 'echo $HOME'

I can get

/home/shawk

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.

  • 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
2

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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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