Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source ~/.bashrc from bash script does not work

I am trying to create a script to be reload bashrc once but it did not work.

reloader.sh

#!bin/bash
source ~/.bashrc
rm reloader.sh
like image 667
Peyker Avatar asked Sep 13 '25 00:09

Peyker


2 Answers

I had the same problem. The issue is that only interactive shells can access whatever you have defined in your .bashrc(Aliases and so on)

To make your shell-script interactive use a shebang with parameter:

#!/bin/bash  -i
like image 115
Qohelet Avatar answered Sep 15 '25 17:09

Qohelet


You need to use source to run the script:

source reloader.sh

If you just run it as a command, it will run in a new process, so none of the changes that .bashrc makes will affect your original shell process.

like image 34
Barmar Avatar answered Sep 15 '25 17:09

Barmar