Arunko Arunko - 26 days ago 13
Bash Question

Access remote machine's exported variable via ssh

So, what I am trying is this:


  • In
    192.168.1.2
    machine, I had set
    export name=arun
    in
    .bash_profile
    file of
    www
    user

  • Then is executed
    source .bash_profile
    .

  • From
    192.168.1.3
    machine, I am trying
    ssh www@192.168.1.2 "echo $name"



This is giving me blank. Is this not supposed to return me
arun
?

Answer

No. You need to escape the variable to be evaluated on the remote shell, not in your local:

ssh www@192.168.1.2 ". .bash_profile;echo \$name"