[SOLVED] Issue with different PATHs for root when on non-login vs login shells in LFS build
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Issue with different PATHs for root when on non-login vs login shells in LFS build
Hey guys
First let me start off by thanking the people behind the LFS project. What an amazing project. I've learned so much doing this. I've completed the LFS book and is basically done with the BLFS as well. I've been following the LFS v9 System V and am running GNOME. I have installed Firefox, Libreoffice, VLC, Transmission and a whole lot of other stuff. My build is nearly worthy of being a daily driver as far as my laptop goes.
I have a few various small issues though. One of them is that the $PATH for my normal user and root are not the same with the path for my normal user being as it should, but root has a much smaller path variable, but only when using a non-login shell like Gterm. When I login to a TTY, like if I don't boot into the GUI, all the paths are correct.
I understand this is due to all the various bash scripts, and there are a number of them. To me this seems slightly more complicated than it needs to me.
To the best of my knowledge it seems like the scripts in /etc/profile.d are not executed for the root user when in GNOME and Gterm as it seems the missing paths are the ones found there.
One of them is that the $PATH for my normal user and root are not the same with the path for my normal user being as it should
what do you think, how should it be set?
Quote:
Originally Posted by bionor
but root has a much smaller path variable,
yes, this is normal, and not only in LFS, but in [almost] any other distro
Quote:
Originally Posted by bionor
but only when using a non-login shell like Gterm. When I login to a TTY, like if I don't boot into the GUI, all the paths are correct.
You need to understand the difference between the login shell and non-login shell, also the difference between interactive and non-interactive shell.
Speaking about bash, you can see the man page (see section invocation) and you will see how are the different files are used (during start of the shell).
Quote:
Originally Posted by bionor
I understand this is due to all the various bash scripts, and there are a number of them.
I do not really understand how is it related to PATH.
Quote:
Originally Posted by bionor
To the best of my knowledge it seems like the scripts in /etc/profile.d are not executed for the root user when in GNOME and Gterm as it seems the missing paths are the ones found there.
gnome and other terminals execute the shell as non-login shell, but probably that can be configured.
Root lacks several sbin paths for instance, but only when logged into gnome and using gterm. The reason I found out about this is that I installed OpenVPN which installed into /usr/local/sbin which was not in root's path when logged in via a non login shell. Then I found out it's there if I log in directly to a console from boot. There might be supposed to be a difference between normal users and root, but not for the root user itself depending on whether you're on login shell or not, except perhaps in special cirumstances.
I've managed to resolve the issue for now though by copying this from /etc/profile into "~/.bashrc":
Code:
for script in /etc/profile.d/*.sh ; do
if [ -r $script ] ; then
. $script
fi
done
As I mentioned, it seems that when using a non-login shell it doesn't read /etc/profile, which as I understand it, it should, or it could be that some of the later scripts overrides it. /etc/profile should be the first script to be read, independently of whether one's on a login or non-login shell, if I'm correct.
Quote:
Originally Posted by pan64
You need to understand the difference between the login shell and non-login shell, also the difference between interactive and non-interactive shell.
Yes, I do. I tried to inform of that by specifying that the difference seems to be between login shells and non-login shells, but I could have made that clearer perhaps.
EDIT: I've changed the title of my OP to better reflect the actual issue.
It's a pity that graphical logins no longer behave like logins.
They do not run /etc/profile and .profile
These should run once - at login.
Some distros take care, e.g. by running /etc/profile from /etc/bash.bashrc
If that's not the case in your distro then I suggest to run /etc/profile in your .bashrc
The /etc/profile should run the /etc/profiles.d/ files.
Code:
if [ -z "$MY_PROFILE_RUN" ]
then
export MY_PROFILE_RUN=1
. /etc/profile
fi
The environment variable ensures that it is run once.
(Some distros have such a variable in /etc/profile ...)
Last edited by MadeInGermany; 12-08-2019 at 03:56 AM.
Reason: typos
It's a pity that graphical logins no longer behave like logins.
They do not run /etc/profile and .profile
Oh really? Well that explains it. I was told /etc/profile was the first one to be run independently of login vs non-login. Thanks! I'll mark it as solved now.
Oh really? Well that explains it. I was told /etc/profile was the first one to be run independently of login vs non-login. Thanks! I'll mark it as solved now.
That is false.
Quote:
(man bash)
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.
During graphical login there will be no bash invoked as interactive login shell. But anyway, you can tell your terminal to run bash with --login.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.