当我启动 XTerm 时,我的 .bashrc 没有获得来源

Law*_*eng 1 bash xterm

我的~/.bashrchttps : //pastebin.com/VA7RLA2E

我的~/.Xresourceshttps : //pastebin.com/qSF1z0w4

如何让 XTerm.bashrc在启动时自动获取?目前,每当我打开一个新的 XTerm 窗口时,它都不会提供~/.bashrc.

我的操作系统是 Ubuntu 18.04。

Kus*_*nda 5

在您的~/.Xresources文件中,您有一行

xterm*loginShell: true
Run Code Online (Sandbox Code Playgroud)

这将使 XTerm 作为登录 shell 启动 shell 会话。当bash作为登录 shell 运行时,它会读取您的~/.bash_profile文件,但不会读取~/.bashrc(此文件由非登录交互会话~/.bash_profile读取),除非source显式读取它。

您有两个选择:

  1. 删除~/.Xresources指定 shell 应该是登录 shell 的行。您可能必须退出图形登录会话才能重新读取此文件并使更改生效。
  2. 使您的~/.bash_profile文件成为source您的~/.bashrc文件,同时确保您的~/.bashrc文件不会同时获取~/.bash_profile文件(这会造成无限循环)。

    如何执行此操作的示例(这将添加到~/.bash_profile文件中):

    if [ -o interactive ] && [ -f ~/.bashrc ]; then
       source ~/.bashrc
    fi
    
    Run Code Online (Sandbox Code Playgroud)

    如果您的系统尚未完成,您可能需要为/etc/profilevs/etc/bash.bashrc或系统上的任何位置执行类似的bashrc操作。然而,正如/etc/profile所有类似 Bourne 的 shell 所读到的,不仅仅是bash,它需要稍微调整一下:

    if [ -n "$BASH" ] &&
       [ "$BASH" != /bin/sh ] &&
       [ -o interactive ] &&
       [ ! -o posix ] &&
       [ -f /etc/bash.bashrc ]
    then
      source /etc/bash.bashrc
    fi
    
    Run Code Online (Sandbox Code Playgroud)