su - login -c cmd ignores variable environments from rc user files. Reproducible: Always Steps to Reproduce: 1. Adding to ~/.bashrc a some user: echo "export AAA=bbb" >> ~/.bashrc Contents of the user's catalogue: $ ln -s ~/.bashrc .bash_login $ ln -s ~/.bashrc .profile $ ls -la $ ls -l .bash* Dec 3 19:15 .bash_login -> .bashrc Dec 3 19:15 .profile -> .bashrc Nov 13 2008 .bash_logout Nov 13 2008 .bash_profile Nov 13 2008 .bashrc $ cat .bash_profile # /etc/skel/.bash_profile # This file is sourced by bash for login shells. The following line # runs your .bashrc and is recommended by the bash info pages. [[ -f ~/.bashrc ]] && . ~/.bashrc Checking: $ source .bashrc $ env | grep AAA AAA=bbb Here is OK. 2. Run from root: # su - support -c "env" SHELL=/bin/bash TERM=screen USER=support PATH=/bin:/usr/bin PWD=/home/staff/support SHLVL=1 HOME=/home/staff/support LOGNAME=support _=/bin/env Variable AAA isn't seen anywhere. Expected Results: # su - support -c "env" SHELL=/bin/bash TERM=screen USER=support PATH=/bin:/usr/bin PWD=/home/staff/support SHLVL=1 HOME=/home/staff/support LOGNAME=support AAA=bbb _=/bin/env
Isn't it .bash_profile that gets sourced by a login terminal rather than .bashrc? What's in the .bash_profile you have laying in that home directory?
I don't know what goes first sourced but wherever I put variables they are ignored. As for .bash_profile contents I wrote it in my initial message. $ cat .bash_profile # /etc/skel/.bash_profile # This file is sourced by bash for login shells. The following line # runs your .bashrc and is recommended by the bash info pages. [[ -f ~/.bashrc ]] && . ~/.bashrc
this is done on purpose. a login shell implies interactivity, but the -c option implies no interactivity. you cant have it both ways. it's trivial to change in the source: src/su.c: /* * Use the shell and create an argv * with the rest of the command line included. */ - argv[-1] = shellstr; + argv[-1] = cp; feel free to e-mail upstream with your concerns, but i dont believe the current behavior to be a bug
Thank you, the patch solves my problem. But in case of login non-interactivity should the environment variables be sourced from ~/.bash_profile?
but .bash_profile should be able to assume an interactive shell, which is bad