Ho scoperto che quelli sono .bash_profile
, .bashrc
, .bash_login
, .profile
.
Qual è la sequenza di lettura tra loro?
Risposta accettata:
Fondamentalmente, se è una shell di accesso, è fonte di /etc/profile
quindi .bash_profile
. Se non è una shell di accesso, ma sei su un terminale, è fonte di /etc/bash.bashrc
quindi .bashrc
.
Ma in realtà è molto più complicato.
Il modo in cui leggo la pagina man:
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
È una shell di accesso ogni volta che la shell viene eseguita come -bash
(notare il segno meno) o con il -l
opzione. Questo di solito accade quando accedi usando il login
comando (le console virtuali Linux lo fanno), su ssh o se l'emulatore di terminale ha l'opzione "login shell" abilitata.
È una shell interattiva ogni volta che lo standard input è un terminale o bash è stato avviato con -i
opzione. Nota che se la shell è anche una shell di accesso, bash non controlla se la shell è interattiva. Per questo motivo, .bash_profile
di solito contiene il codice di origine .bashrc
, così puoi condividere le stesse impostazioni tra shell interattiva e di accesso.