running .bashrc versus new login

7

1

I added new alias into .bashrc

Running .bashrc doesn't create that alias but new log in yes.

Could you somebody explain why is that so and how I can test if the new .bashrc works without doing test log in?

Radek

Posted 2010-08-12T01:10:04.217

Reputation: 2 914

Answers

10

"exec bash" should do it. Basically just restarts the bash shell, reading .bashrc in the process.

hotei

Posted 2010-08-12T01:10:04.217

Reputation: 3 645

let me try that... so why executing .bashrc doesn't work? – Radek – 2010-08-12T01:46:06.160

2When you execute ".bashrc" by itself it starts a new bash shell up (reading your new aliases) but keeps the old one active. Then it "does nothing" since you didn't ask it to do anything, and exits back to the old shell, restoring all your old aliases. – hotei – 2010-08-12T01:53:32.663

3When you "exec bash" it REPLACES your old shell with the new one. "man exec" for all the details of how this works. It's also useful if your root account runs sh but you like bash better for some things (cwd in prompt in my case). You can make root run bash by "exec bash" as root. – hotei – 2010-08-12T01:56:49.007

very nice explanation ... – Radek – 2010-08-12T04:42:10.157

8

You can source the file using . or source:

. ~/.bashrc

or

source ~/.bashrc

That will re-read and execute the lines in the file in the current session.

Paused until further notice.

Posted 2010-08-12T01:10:04.217

Reputation: 86 075

works nicely.... – Radek – 2010-08-12T04:59:46.917