Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 had a problem that my cron script wasnt loading the environment variables so I added the following line:

bash /root/.bash_profile

This seems to have no effect and the path variables are not being set correctly. How do I run the bash_profile script

share|improve this question
up vote 4 down vote accepted

bash /root/.bash_profile will create a new bash process, run that file (and I assume set your env variables while doing so), and then exit, taking those newly set env variables with it.

Try . /root/.bash_profile. Or source /root/.bash_profile. That will execute the file in the current bash process, so your env variables will be available to the current process.

You may also want to use #!/bin/bash instead of #!/bin/sh if you're going to do bash-style invocations.

share|improve this answer

. /root/.bash_profile or source /root/.bash_profile. which says to run that file in the current shell. Your method runs .bash_profile in s subshell, That sets up the variables in the subshell, then this subshell exits, taking these variables with it.

share|improve this answer

If you want to include the variables in the .bash_profile file, you need to source it in your script.

Simply executing the script will not include the exported variables.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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