Page MenuHomePhabricator

'become' doesn't load ~/.bashrc
Closed, InvalidPublic

Description

When you use 'become' to log into a shared account, ~/.bashrc isn't run.

catrope@tools-login:~$ become visualeditor
local-visualeditor@tools-login:~$ cat ~/.bashrc

Shortcuts

alias ..='cd ..'
alias ll='ls -ahlF --color=auto'
alias l='ll'

Environment

export PATH=$HOME/bin:$PATH;

local-visualeditor@tools-login:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
local-visualeditor@tools-login:~$ . ~/.bashrc
local-visualeditor@tools-login:~$ echo $PATH
/data/project/visualeditor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin

Adding $HOME/bin to $PATH would probably be a nice thing to do in general.


Version: unspecified
Severity: normal

Details

Reference
bz50249

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:08 AM
bzimport added a project: Toolforge.
bzimport set Reference to bz50249.
Catrope created this task.Jun 26 2013, 5:59 PM
coren added a comment.Jun 26 2013, 6:06 PM

Works as designed.

become, through sudo, creates an interactive login shell. To quote from the bash info page:

" When Bash is invoked as an interactive login shell, or as a

non-interactive shell with the `--login' option, 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."

A thing many users may want to do to simplify things is to have a ~/.profile that sources ~/.bashrc (in addition or instead of login-specific behaviour) so that the latter gets sourced regardless of how the shell was invoked.