bash prompt foi resetado toda vez que eu fizer login

2

Eu perguntei esta questão há algum tempo atrás sobre o shell não exibir o caminho. Recentemente eu descobri que o .bashrc não é originado (e isso deve ser um prática normal ? Atualmente, o prompt de comando do shell é assim:

-bash-4.3#

depois de executar source .bashrc , posso obter o prompt de comando do shell esperado:

root@ubuntu2011:~#

em que ubuntu2011 é o nome da máquina. Como posso fazer com que o prompt se pareça com o último sempre que eu fizer login?

p.s. o .bashrc é de: cp /etc/skel/.bashrc ~/.bashrc

UPDATE : o conteúdo de ~/.profile é o seguinte:

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n

e echo $BASH retornam /bin/bash

UPDATE : Respostas das perguntas do @ terdon:

  1. Como faço para acessar o servidor?

I use ssh [email protected] to login as root

  1. Esses comandos são executados como root?

Yes.

UPDATE : a saída de ls -l ~/.{profile,bashrc,bash_profile,bash_login} :

ls: cannot access /root/.bash_login: No such file or directory
-rw-r--r-- 1 root root   63 Dec 24  2012 /root/.bash_profile
-rw-r--r-- 1 root root 3637 May 17 17:00 /root/.bashrc
-rw-r--r-- 1 root root  140 Apr 23  2010 /root/.profile
    
por Raptor 17.05.2016 / 11:21

2 respostas

2

Isso acontece porque você está fazendo login através de ssh . Tudo se resume às diferenças entre os shells de login e não-login. Quando você se conecta via ssh, você executa um shell interativo de login. Como explicado em man bash , esse tipo de shell irá:

When bash is invoked as an interactive login shell, or as a non-inter‐ active shell with the --login option, it first reads and executes com‐ mands 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. The --noprofile option may be used when the shell is started to inhibit this behavior.

Em outras palavras, ~/.bashrc é ignorado por padrão ao executar shells de login. A solução simples é fornecer explicitamente a partir de um dos arquivos que são lidos. Como você pode ver acima, os shells de login primeiro tentarão ler ~/.bash_profile e, se isso não existir, ~/.bash_login , e se isso também não existir, eles lerão ~/.profile . Como você tem um arquivo ~/.bash_profile , precisará adicionar essas linhas a ele:

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
    
por 17.05.2016 / 12:18
0

Coloque isso no seu ~ / .profile

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
    
por 17.05.2016 / 11:41

Tags