No RHEL7, vejo um comportamento diferente com scripts de inicialização quando eu su para um usuário com /bin/sh ou /bin/bash como o shell, apesar do fato de /bin/sh apontar para /bin/bash
Eu tenho os seguintes scripts configurados para o usuário:
/home/my_user/.profile
echo Hello from .profile
/home/my_user/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
echo Hello from .bash_profile
/home/my_user/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
echo Hello from .bashrc
Agora, quando eu su e especifique /bin/bash , recebo a seguinte saída.
[batwad@hellodave ~]$ sudo su -s /bin/bash my_user
Hello from .bashrc
[my_user@hellodave batwad]$
Isso significa que .bash_profile não foi executado? Afinal, não vejo "Olá de .bash_profile"
Agora, quando eu su e especifique /bin/sh (que vincula a /bin/bash de qualquer maneira), recebo a seguinte saída.
[batwad@hellodave ~]$ sudo su -s /bin/sh my_user
sh-4.2$
Nenhum eco e um prompt de shell diferente. O que dá?
Atualizar
Seguindo a resposta de redseven, tentei adicionar -l e consegui outro comportamento!
[bawtad@hellodave ~]$ sudo su -l -s /bin/sh my_user
Last login: Thu Aug 16 11:44:38 UTC 2018 on pts/0
Hello from .profile
-sh-4.2$
É .profile que é usado desta vez! Observe que a parte "Último login" não foi exibida na primeira tentativa.