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.

  • 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, 2018 at 8:31
  • 1
    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, 2018 at 18:28
  • Use absolute paths: source /home/${SUDO_USER}/.bashrc Jan 3, 2021 at 17:21

2 Answers 2


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, 2018 at 19:56
  • This answer seems tangential to the OP question (an irrelevant solution). Jan 3, 2021 at 17:27

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

  • 2
    OP wants the script to modify the calling shell in some way...
    – Zanna
    Dec 15, 2018 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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