2

I'm creating a script for managing my dotfiles and I want to source my ~/.bashrcfile automaticaly for the current bash.

But I found that when in my script write :

source ~/.bashrc

it will source the .bashrc file for the execution of the script only. And as my shell is already started it will not reload the configuration.

Do you have a solution for reloading the file in the script-caller bash ?

(Correct me if you think I don't use the right terms)

  • 2
    Instead of executing your script, source your script. If done this way, the effects of the source ~/.bashrc line within your script will remain after the script finishes. (Other changes made by the script will also remain. So, it should clean up any unwanted temp variables or settings before it completes.) – John1024 Sep 21 '14 at 23:40
  • OK great ! thanks but is there any way a method in a script to do it automatically ? If I want to execute it like so ./path/to/the/file.sh – nobe4 Sep 21 '14 at 23:45
5

At the end of your script, you can do:

kill -USR1 $PPID

so that it will send the USR1 signal to the parent process, which is the bash shell from which you run the script. In your .bashrc, you can trap this USR1 signal to do whatever you like, such as

source ~/.bashrc

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.