I am trying to write a script that will:

  1. Copy files to a server (I already have a script copy.sh that does this task)
  2. ssh to that server
  3. cd to the directory where the files I just copied are
  4. run make
  5. copy the resulting binary from make to another location.

My script looks like this:


#run my script that copies the files

#TARGET is also a var in copy.sh so I make sure it's set properly here

ssh $BUILDSERV "cd $BUILDDIR && make && scp ./my_bin $TARGET"

The issue is that a program I want to run as part of make is not in my PATH. My .bash_profile has a export PATH=$PATH:/my/bin/ line, but it seems that bash_profile is not being read when I ssh in.

Is there a way to change my ssh invocation or script in general to make it read my .bash_profile?

  • Have you considered using a forced command? Commented Aug 6, 2014 at 16:43

1 Answer 1


The following should work:

ssh $BUILDSERV "source ~/.bash_profile && cd $BUILDDIR && make && scp ./my_bin $TARGET"

The source shell builtin reads a file and executed the commands in the same shell (unlike simply calling the script, which invokes a separate shell).

When invoked as login shell, bash executes the .bash_profile, if it exists, in exactly the same way as source does, therefore the effect will be the same.


You must log in to answer this question.

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