登录时未获取 .bash_profile

登录时未获取 .bash_profile

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

# /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\] '

但是,这些更改没有任何效果。登录后,我没有在文件中声明别名。$PS1也不会受到影响。据我所知,用户的.bashrc脚本来自.bash_profile位于用户主目录中的脚本。因此,出于测试目的,我已将以下行添加到我的 .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

test.txt登录后没有出现在我的主目录中。似乎.bash_profile登录时没有调用。

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

答案1

你能尝试手动运行 bash 吗?只需

bash

对于交互式 shell,它将使用.bashrc文件和

bash -l

用于登录 shell 来测试/etc/profile~/.bash_profile文件。

此外,你可以尝试使用 strace 实用程序跟踪 bash 进程的系统调用,并检查配置文件是否至少打开了

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

答案2

谢谢你,德苏姆斯基,感谢您的回答。

确实,.bashrc当我手动运行时,肯定是源bash。这让我想到了一个问题:“哪个shell设置为我的用户的登录shell?”。是。尽管符号链接针对的是,但/bin/sh在我用它替换它之后,问题就消失了。/bin/bash/bin/sh/bin/bash

相关内容