简体   繁体   English

使用 source.bashrc 后别名未更新

[英]Alias not updated after using source .bashrc

I am testing the bash behavior on login (terminal 1), but I got confused about its interaction with alias:我正在测试登录(终端 1)时的 bash 行为,但我对它与别名的交互感到困惑:

I opened with vim.bashrc and add this line:我用vim.bashrc打开并添加以下行:

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并将其保存为:x然后我使用source.bashrc模拟新登录 session 并在别名列表中找到它

But I removed the alias from.bashrc and use source.bashrc again I saw that alias ls='ls -l' was still available.但是我从 .bashrc 中删除了别名并再次使用source.bashrc我看到alias ls='ls -l'仍然可用。 On the other hand, opening new shell terminal (terminal 2) the problem was solved.另一方面,打开新的shell端子(端子2)问题就解决了。

Question: Why alias ls='ls -l' was not removed on the first terminal?问题:为什么alias ls='ls -l'在第一个终端上没有被删除?

Sourcing .bashrc doesn't clear what you have defined so far.采购.bashrc并不清楚您到目前为止所定义的内容。 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:最后,如果您想使用全新的 shell 重新开始,您当然可以关闭 session 并重新打开一个,但如果这不是那么容易(ssh)或不受欢迎,这里有一个几乎相同的命令:

$ exec bash

(you may also add the -l option to simulate a login shell, thus reading your ~/.bash_profile file) (您也可以添加-l选项来模拟登录 shell,从而读取您的~/.bash_profile文件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM