Reload .bashrc file for parent shell

11,902

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
Share:
11,902

Related videos on Youtube

nobe4
Author by

nobe4

Updated on September 18, 2022

Comments

  • nobe4
    nobe4 over 1 year

    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)

    • John1024
      John1024 over 9 years
      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.)
    • nobe4
      nobe4 over 9 years
      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