Zjistil jsem, že to jsou .bash_profile
, .bashrc
, .bash_login
, .profile
.
Jaká je sekvence čtení mezi nimi?
Přijatá odpověď:
V zásadě, pokud se jedná o přihlašovací shell, je zdrojem /etc/profile
pak .bash_profile
. Pokud to není přihlašovací shell, ale jste na terminálu, zdroj /etc/bash.bashrc
pak .bashrc
.
Ale ve skutečnosti je to mnohem složitější.
Způsob, jakým čtu manuálovou stránku:
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
Je to přihlašovací shell, kdykoli je shell spuštěn jako -bash
(všimněte si znaménka mínus) nebo pomocí -l
volba. K tomu obvykle dochází, když se přihlásíte pomocí login
příkaz (toto dělají virtuální konzole Linuxu), přes ssh, nebo pokud má váš emulátor terminálu povolenou možnost „přihlašovací shell“.
Je to interaktivní shell, kdykoli je standardním vstupem terminál nebo když byl bash spuštěn pomocí -i
volba. Všimněte si, že pokud je shell také přihlašovacím shellem, bash nekontroluje, zda je shell interaktivní. Z tohoto důvodu .bash_profile
obvykle obsahuje zdrojový kód .bashrc
, takže můžete sdílet stejná nastavení mezi interaktivními a přihlašovacími shelly.