Take the 2-minute tour ×

I'm new to bash shell scripting, and have come across a challenge. I know I can reload my ".profile" file by just doing:

. .profile

but I'm trying to execute the same in a bash script I'm writing and it is just not working. Any ideas? Anything else I can provide to clarify?


share|improve this question
As Ignacio points out below, your script is running in a subshell. The subshell can't modify the main shell (the child process can't modify its parent). So you need to "source" the script by using the "." command (which can also be spelled as "source"). So if your script wants to, say, modify environment variables, you need to do something like "source myscript" or ". myscript" (they both mean the same thing). This will modify your main shell's environment. (Which I think is what you're trying to do, let me know if this is wrong.) –  bstpierre Jul 20 '10 at 3:08

5 Answers 5

up vote 46 down vote accepted

Try this to reload your current shell:

source ~/.profile
share|improve this answer

The bash script runs in a separate subshell. In order to make this work you will need to source this other script as well.

share|improve this answer
I'm not sure (still new to all of this) what you exactly mean by "source"-ing the other script. Could please expand a little on that. However I have tried: $ . ~/.profile $ . /etc/profile with no success. Thank you so much. –  Amir R. Jul 18 '10 at 5:07
@amirrustan: Your script will need to source your .profile file something like this: . $HOME/.profile and you will need to start your script by sourcing it also. Something like . /path/to/yourscript –  Dennis Williamson Jul 18 '10 at 8:35
@amirrustam please read superuser.com/questions/176783/… –  lesmana Aug 23 '10 at 3:44

To get more clarity about source (ing) and other stuffs, read this 4 Ways of Executing a Shell Script in UNIX / Linux

share|improve this answer

Try this:

source .bash_profile
share|improve this answer


# .... some previous code ...
# help set exec | less
set -- 1 2 3 4 5  # fake command line arguments
exec bash --login -c '
echo $0
echo $@
echo my script continues here
' arg0 "$@"
share|improve this answer

Your Answer


