Qual é o arquivo conf entre o login e o shell de não-login?

4

Descobri que esses são .bash_profile , .bashrc , .bash_login , .profile .

Qual é a sequência de leitura entre eles?

    
por sam 25.07.2012 / 16:41

1 resposta

6

Basicamente, se for um shell de login, ele usa /etc/profile then .bash_profile . Se não for um shell de login, mas você estiver em um terminal, ele obterá /etc/bash.bashrc then .bashrc .

Mas na verdade é muito mais complicado.

A maneira como eu leio a página 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

É um shell de login sempre que o shell é executado como -bash (observe o sinal de menos) ou com a opção -l . Isso geralmente acontece quando você efetua login usando o comando login (os consoles virtuais do Linux fazem isso), sobre o ssh, ou se o emulador de terminal tem a opção "login shell" ativada.

É um shell interativo sempre que a entrada padrão é um terminal, ou o bash foi iniciado com a opção -i . Observe que, se o shell também for um shell de login, o bash não verificará se o shell é interativo. Por esse motivo, .bash_profile geralmente contém código para a origem .bashrc , para que você possa compartilhar as mesmas configurações entre os shells interativos e de login.

    
por 25.07.2012 / 18:28