4

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
2
  • 1
    You need to run the script with source. Otherwise it runs in a subshell, and the changes that .bashrc makes won't affect your original shell. Commented Mar 25, 2017 at 7:04
  • If you want to make a script to load .bashrc into your current shell (the one in your terminal) just source from command line, it it is the script that needs the .bashrc then your code should actually work. Technically the answer with the tick is wrong (whatever you wanted it's a stupid way to go about it) while the one telling you to change the shebang is correct. You should pose your question more clearly. Commented Dec 3, 2020 at 6:17

2 Answers 2

11

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
Sign up to request clarification or add additional context in comments.

Comments

8

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.

10 Comments

Thanks a lot. It worked in executing source ~/.bashrc command but it seems that the code is ignoring "rm reloader.sh" and it keeps reloading the bashrc.. Any idea how to solve this?? I am executing this script from bashrc as a way of reloading bashrc once.
Why do you need to reload bashrc when you're already loading bashrc?
Is it getting an error when it tries to rm reloader.sh?
I am trying to open a python server script in bashrc but it gave me a binding error. However If I close the terminal and reopen it again, the server starts working properly. So I thought If I can do something to refresh the bashrc, the socket can work properly.
Are you sure it's getting there? If you put echo removing reloader.sh before it, do you see the message?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.