Qual é a diferença entre um shell 'Login' e um 'Interactive'?

46

Qual é a diferença entre um shell bash "Login" e um "Interactive"? Eu citei a Wikipedia abaixo, mas alguém pode dar uma resposta melhor?

EDIT: Este é um wiki da comunidade então talvez ao invés de votar para fechar você poderia fornecer exemplos de quais situações chamam para qual tipo de $ SHELL

Startup scripts

When Bash starts, it executes the commands in a variety of different scripts.

When Bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

When a login shell exits, Bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force Bash to read and execute commands from file instead of ~/.bashrc.

    
por gyaresu 16.05.2009 / 15:04

1 resposta

16

Nos arquivos de perfil do seu shell de login, você pode configurar algumas coisas que você usará durante a sua sessão e que só precisam ser feitas uma vez. Algumas ideias:

  • crie um arquivo temporário contendo o endereço IP do qual você se conectou. Posteriormente, você poderá incluí-lo em alguns scripts definindo regras de firewall.
  • execute o ssh-agent, solicite suas chaves SSH e armazene as variáveis de ambiente do agente SSH em um arquivo.
  • se for uma máquina limitada, e seus colegas de trabalho quiserem estar cientes dos logins uns dos outros, escreva (1) mensagens informando sobre seu login.

Nos arquivos de um shell de não-login ( .bashrc ) você deve configurar seu shell:

  • Solicitação de fantasia
  • definir aliases
  • definir opções do histórico
  • definir funções personalizadas do shell
  • exporte variáveis de ambiente, (talvez PAGER, EDITOR se configurações do sistema forem ruins)
  • carregue variáveis do ssh-agent salvas em .bash_profile

Normalmente, você incluiria .bashrc de .bash_profile com o seguinte. Em seguida, o shell de login obtém todas as suas personalizações e o .bash_profile file não precisa duplicar as coisas que já estão em .bashrc .

[[ -f ~/.bashrc ]] && . ~/.bashrc
    
por 21.09.2015 / 11:59