Linux

登錄期間未獲取 .bash_profile

  • June 14, 2016

我已經在.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也不受影響。AFAIK 使用者的.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

謝謝你,dsumsky,你的回答。

確實,當我手動.bashrc執行時,肯定是有源的。bash這讓我想到了“什麼外殼設置為我的使用者的登錄外殼?”這個問題。它是/bin/sh。儘管符號連結的目標/bin/bash是./bin/sh``/bin/bash

您可以嘗試手動執行 bash 嗎?簡單地

bash

對於將使用.bashrc文件和

bash -l

用於登錄外殼測試/etc/profile~/.bash_profile文件。

此外,您可以嘗試使用 strace 實用程序跟踪 bash 程序的系統呼叫,並檢查是否至少打開了配置文件

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

引用自:https://serverfault.com/questions/526366