(as root): echo 'echo $PATH' | su glibc
/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
(as root): su glibc
package glibc:/usr/src/glibc> echo $PATH
/usr/lib/pkgusr:/bin:/usr/bin:/tools/bin
I am using the first approach to automate the LFS build
process. It
looks like in this case the .bash_profile file is not read.
Why?
The section INVOCATION of the bash manpage will tell you
exactly what
files bash sources when. An excerpt (emphasis added):
"[...]An interactive shell is one started without non-option
arguments
and without the -c option whose STANDARD INPUT and
output are both CONNECTED TO TERMINALS[...]"
So because in your case standard input is connected to a pipe,
bash is
started in non-interactive mode. In non-interactive mode it
doesn't read
.bash_profile unless specifically instructed to do so. Read the
bash
manpage for details.
Having read the whole INVOCATION section several times, I would
like to focus your attention on the following excerpt from it:
"[...]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 fils /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.[...]"
I guess all this (along with the excerpt from the previous post)
means that in the first case (echo 'echo $PATH' | su glibc) bash
is started as a non-interactive shell without the --login option.
Now, let's have a look at an excerpt from the su manpage:
"[...]The optional argument - may be used to provide an
environment similar to what the user would expect had the user
logged in directly.[...]"
Does this mean that 'su - glibc' should always start bash
as a login shell, i.e. with --login? If no, what is "an
environment similar to what the user would expect had the user
logged in directly"? If so, then why do the following commands
still cause bash not to read ~/.bash_profile:
echo 'echo $PATH' | su - gblic
stdout: /usr/bin:/bin
echo 'echo $PATH' | su glibc -l
stdout: /usr/bin:/bin
The su manpage also says:
"[...]Additinoal arguments may be provided after the username, in
which case they are supplied to the user's login shell.[...]"
I tried passing -i to su (after the username) hoping that -i will
be passed along to bash and cause it to start in innteractive
mode and thus read ~/.bash_profile. Unfortunately, this did
not happen and I wonder why:
echo 'echo $PATH' | su - gcc -i
stderr: su: invalid option -- i
stderr: Try 'su --help' for more information.
P.S. I am sorry for discussing this non-LFS matter here but
trying to understand how su invokes bash puts me at a loss.
--
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page