2

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.

Zanna
  • 70,465
Wayne
  • 51

2 Answers2

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.

Yay!

Wayne
  • 51
0

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"
fi

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

EDIT

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

kostia
  • 111