Ich habe festgestellt, dass dies .bash_profile
sind , .bashrc
, .bash_login
, .profile
.
Wie ist die Lesesequenz zwischen ihnen?
Akzeptierte Antwort:
Wenn es sich um eine Login-Shell handelt, bezieht sie im Grunde /etc/profile
dann .bash_profile
. Wenn es sich nicht um eine Login-Shell handelt, Sie sich aber an einem Terminal befinden, bezieht es /etc/bash.bashrc
dann .bashrc
.
Aber es ist tatsächlich viel komplizierter.
So wie ich die Manpage gelesen habe:
if bash_mode; then
if login_shell; then
if test -e /etc/profile; then source /etc/profile; fi
if test -e .bash_profile; then source .bash_profile
elif test -e .bash_login; then source .bash_login
elif test -e .profile; then source .profile; fi
elif interactive_shell || remote_shell; then
if test -e /etc/bash.bashrc; then source /etc/bash.bashrc
if test -e .bashrc; then source .bashrc; fi
elif test -n "$BASH_ENV"; then
source "$BASH_ENV"
fi
elif sh_mode; then
if login_shell; then
if test -e /etc/profile; then source /etc/profile; fi
if test -e .profile; then source .profile; fi
elif interactive_shell; then
if test -n "$ENV"; then
source "$ENV"
fi
fi
fi
Es ist immer dann eine Login-Shell, wenn die Shell als -bash
ausgeführt wird (beachten Sie das Minuszeichen) oder mit dem -l
Möglichkeit. Dies geschieht normalerweise, wenn Sie sich mit dem login
anmelden Befehl (virtuelle Linux-Konsolen tun dies), über ssh oder wenn Ihr Terminal-Emulator die Option „Login-Shell“ aktiviert hat.
Es ist immer dann eine interaktive Shell, wenn die Standardeingabe ein Terminal ist oder Bash mit dem -i
gestartet wurde Möglichkeit. Beachten Sie, dass Bash nicht überprüft, ob die Shell interaktiv ist, wenn die Shell auch eine Login-Shell ist. Aus diesem Grund .bash_profile
enthält normalerweise Code zur Quelle .bashrc
, sodass Sie die gleichen Einstellungen zwischen interaktiven und Login-Shells teilen können.