ubuntu中 .bashrc 没有被执行(.bashrc not executed when opening new terminal)

r囧r小猫 2023-07-10 12:50 75阅读 0赞

.bashrc 没有被执行

当我在Ubuntu 12.04中打开新的终端窗口时,.bashrc中的代码不执行。 创建.bash_aliases文件时,我注意到了这一点。 当我打开一个新终端时,别名没有显示。 但是,当我输入source .bashrc时,别名确实出现了。

.bashrc应该在每次打开新的终端窗口时运行,对吗?

我如何做到这一点?

如何解决

它不一定运行; 在标准.bashrc的顶部是此注释:

  1. # ~/.bashrc: executed by bash(1) for non-login shells.
  2. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
  3. # for examples

我相信可以选择是否将bash终端作为登录shell运行。 在Ubuntu中,gnome-terminal通常不作为登录shell运行,因此.bashrc应该直接运行。

对于登录外壳程序(如虚拟终端),通常运行〜/.profile文件,除非您具有〜/.bash_profile或〜/.bash_login,但默认情况下不存在。 默认情况下,Ubuntu仅使用.profile

标准〜/ .profile中包含以下内容:

  1. if [ -n "$BASH_VERSION" ]; then
  2. # include .bashrc if it exists
  3. if [ -f "$HOME/.bashrc" ]; then
  4. . "$HOME/.bashrc"
  5. fi
  6. fi

如果可用,它将运行.bashrc-假定环境中存在$ BASH_VERSION。 您可以通过输入命令echo $ BASH_VERSION进行检查,它应该显示一些有关版本号的信息-不能为空。


原文: [.bashrc not executed when opening new terminal] https://askubuntu.com/questions/161249/bashrc-not-executed-when-opening-new-terminal

发表评论

表情:
评论列表 (有 0 条评论,75人围观)

还没有评论,来说两句吧...

相关阅读