.bash_profile在login期间不是来源的

我在位于我的主目录的.bashrc文件中声明了一个别名。 PS1环境variables的导出也已经添加到这个文件中。

 # /etc/skel/.bashrc # # This file is sourced by all *interactive* bash shells on startup, # including some apparently interactive shells such as scp and rcp # that can't tolerate any output. So make sure this doesn't display # anything or bad things will happen ! # Test for an interactive shell. There is no need to set anything # past this point for scp and rcp, and it's important to refrain from # outputting anything in those cases. if [[ $- != *i* ]] ; then # Shell is non-interactive. Be done now! return fi # Put your fun stuff here. alias ll='ls -l' export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \W \$\[\033[00m\] ' 

但是,这些更改没有任何影响。 login后,我没有在文件中声明的别名。 $PS1也不受影响。 AFAIK用户的.bashrc脚本来源于位于用户主目录中的.bash_profile脚本。 所以为了testing的目的,我将下面这行代码添加到我的.bash_profile文件中:

 echo hello > ~/test.txt 

这是我的.bash_profile文件的全部内容:

 # /etc/skel/.bash_profile # This file is sourced by bash for login shells. The following line # runs your .bashrc and is recommended by the bash info pages. echo hello > ~/test.txt [[ -f ~/.bashrc ]] && . ~/.bashrc 

login后, test.txt不会出现在我的主目录中。 似乎在login过程中不会调用.bash_profile

如何设置系统考虑用户的.bash_profile

你可以尝试手动运行bash吗? 只是

 bash 

交互式shell将使用.bashrc文件和

 bash -l 

用于loginshell来testing/etc/profile~/.bash_profile文件。

此外,您可以尝试使用strace实用程序跟踪bash进程的系统调用,并检查至less打开哪些configuration文件

 strace -f -e open bash strace -f -e open bash -l 

谢谢你, dsumsky ,你的答案。

的确,当我手动运行bash时, .bashrc绝对是源代码。 这让我想起了“为我的用户设置了什么shell作为loginshell?”的问题。 这是/bin/sh 。 这个问题在我用/bin/bashreplace之后就消失了,尽pipe/bin/sh符号链接是针对/bin/bash