Reputation: 53
I am testing the bash behavior on login (terminal 1), but I got confused about its interaction with alias:
I opened with vim .bashrc
and add this line :
alias ls='ls -l'
and save it with :x
then I used source .bashrc
to simulate a new login session and I found it in the aliases list
But I removed the alias from .bashrc and use source .bashrc
again I saw that alias ls='ls -l'
was still available. On the other hand, opening new shell terminal (terminal 2) the problem was solved.
Question: Why alias ls='ls -l'
was not removed on the first terminal ?
Upvotes: 5
Views: 2153
Reputation: 6144
Sourcing .bashrc
doesn't clear what you have defined so far. It just adds the definitions it contains to your current environment.
If you want to undefine a given alias, just type:
$ unalias ls
$ source .bashrc
If you want to undefine all aliases:
$ unalias -a
$ source .bashrc
Finally, if you want to start over with a brand new shell, you can of course close your session and reopen one, but here is an almost identical command in case this is not that easy (ssh) or undesirable:
$ exec bash
(you may also add the -l
option to simulate a login shell, thus reading your ~/.bash_profile
file)
Upvotes: 3