This question already has an answer here:

How do I force the shell I called a script from to reload .bashrc from inside the script?

I'm trying to make a "new box" script that sets everything up the way I like it. Everything works, except for reloading .bashrc.

I know I can "just" do . ~/.bashrc or exec bash or any of the other ways to apply changes after running the script. But it kind of defeats the purpose of making a one-button fix, and coming this far just to get screwed on the last step is driving me nuts lol

I've tried adding all of the source ~./bashrc exec bash stuff to the script, but no joy since it is only reloading it for the script's environment, not the calling shell

I'm still fairly new so it's probably something super obvious which would explain why I couldn't googlefu the answer >.<

any help would be much appreciated.

marked as duplicate by dessert, Eric Carvalho, guntbert, Thomas, muru bash Dec 17 '18 at 2:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Changes are applied for any newly opened terminal, you don’t need to do anything for that. Sourcing .bashrc is only needed to apply the changes for the terminal which runs the script – you don’t really need that, or do you? If so, why? I don’t know of a shorter way than: /path/to/script.bash && . ~/.bashrc – dessert Nov 25 '18 at 8:31
  • the reason i "need" it to source the terminal running the script is because i generally plan to continue working after the script runs. So having to immediately source it afterwards is just annoying after the 50th time doing it lol – Wayne Nov 25 '18 at 18:28

This might not work for everything. And may be doing something I shouldn't be doing.. but for my purposes it gets the job done.

For script.sh if i call it by . script.sh instead of bash script.sh everything seems to run and update accordingly.


  • 1
    of course! source the script to execute it in the current shell :) – Zanna Dec 15 '18 at 19:56

I know it will sound silly, I am also new around here, but what if you exported the environments you needed directly from the script and then added them to the .bashrc for later use?

Let's say i.e. checking if a environmental variable exists and load it:

### MySQL
if [ -z "$MYSQL_HOME" ]; then
    export MYSQL_HOME="/usr/local/mysql"
    export PATH="$MYSQL_HOME/bin:$PATH"

and then copy this segment code to .bashrc as well...


I actually stumbled to this Updating the ~/.bashrc file for a script

  • 1
    OP wants the script to modify the calling shell in some way... – Zanna Dec 15 '18 at 9:43

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