Re: su 5.2.1 does not invoke bash as a login shell when stdin is from a pipe



On 2006-09-09 Sat 18:25:28, Angel Tsankov wrote:
Here's a scenario in which su from coreutils 5.2.1 does not
invoke bash as a login shell:

....test cases snipped...
Is this a problem in su and if so, is there a patch for it?

According to the bash man page, .bash_profile is read for an
interactive
login shell. When standard input is a pipe, the shell is not
interactive, unless bash is invoked with the -i option.

Read and man pages caerfully (emphasys added):
[...] When bash is invoked as an interactive login shell, or as A
NON-INTERACTIVE LOGIN 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_profiles, ~/.bash_login, and ~/.profile, in that order,
and reads and executes commands from the first one that exists
and is readable.[...]

And, according the the su man page, the - option to su should
start a login shell. The /etc/profile file does not exist, so
bash should read ~/.bash_profile which exists and is readable.


That may not precisely correct. My man page (I may use a different set
of tools) says (emphasis added) "The optional argument - may be used
to provide an environment SIMILIAR to what the user would expect HAD the
user logged in directly." I've experienced a similar issue running
commands from vim and this:

su - -l -c foo

works fine. HTH.
.



Relevant Pages