0

I am trying to just do a simple echo $MYVAR on a remote server with Fabric.

The environment variable is in my ~/.bashrc file on the remote host.

I have tried:

run("source /home/<myusername>/.bashrc && echo $MYVAR")

This just prints an empty string. Running it when logged in on the remote machine prints "5", the value in the bashrc file. Does anyone know why this would be?

I need the environment variable to be set from a file on the remote host, and not decided by Fabric.

I am running the ssh commands as <myusername>, so the username seems correct. This seems like a duplicate of this question, except that maybe they were running things as the wrong user. I also tried the shell argument to run, with no luck.

I haven't tried the various context manager-ish things, as they just seem to be a shorthand for command1 && command2.

Community
  • 1
  • 1
dcc310
  • 1,038
  • 1
  • 9
  • 13

1 Answers1

1

First, as explained in the answer you link to, fabric uses a login shell, not and interactive shell, meaning your ~/.bahsrc is not going to be source'd on the remote. You should export your variable in your ~/.bash_profile or ~/.profile.

Without the relevant content of your remote ~/.bashrc it's impossible to tell why your command fails.

Community
  • 1
  • 1
kynan
  • 13,235
  • 6
  • 79
  • 81
  • I likely will not be able to revisit this for a while, but I didn't know there was a difference between ~/.bashrc file and ~/.bash_profile. I was used to seeing the 'profile' on my Mac, and 'rc' on some Ubuntu systems I use, but I thought they were just different names for the same thing. I found [this explanation](http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment) somewhat helpful. Thanks! – dcc310 Feb 03 '16 at 17:57