7

While I understand that source command executes a program in the current shell, I don't quite understand why we need to run source .bashrc to "reload" the .bashrc file.

From my understanding, we do not run any script by adding an alias to .bashrc - with source .bashrc we just "reload" the file.

Why does it not reload automatically?

Probably, I'm missing something.

How does it work under the hood? Why do we need to source this file to get new aliases working without login out?

t7e
  • 298

1 Answers1

10

.bashrc is read only once, when bash starts. It is just so by design (and has always been). If you make any subsequent changes to .bashrc, they won't be applied until .bashrc is re-read. By running source .bashrc, you make exactly this - you tell bash to re-read that file.

Of course you can also start a new copy of bash (by eg. starting a new terminal session), this will cause the new bash process read the .bashrc file again (but there will be no changes in the old session).

BTW. .bashrc file is a script, and by sourcing it, you execute the commands placed in that file. The commands define aliases in your case, but there can be virtually any commands placed in that file.

raj
  • 11,409