SlackwareThis Forum is for the discussion of Slackware Linux.
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.
(Slackware)
I am trying to add /sbin and /usr/sbin to my $PATH but it isn't persisting. I have tried to fix this in two ways, the command "export PATH=$PATH:/sbin:/usr/sbin" and by editing my /etc/profile file. The first method never seems to persist and I have to redo it everytime I open a terminal window and the second has yielded no results, what am I doing wrong and how do I fix it? It may be useful to know that I am doing this as a regular user account.
Last edited by levelfourtwenty; 06-15-2020 at 07:50 PM.
Try editing /etc/login.defs. You'll see ENV_SUPATH has what you want, and ENV_PATH doesn't have the /sbin entries - changing ENV_PATH to be the same as ENV_SUPATH should achieve your goal.
It depends when you want to persist changes to the environment variable PATH.
If you use bash, start a graphical session, and open a terminal emulator, then you need to modify your .bashrc file:
export PATH=/sbin:/usr/sbin:$PATH
If you want to have such paths added to PATH since you log in (no graphical session is started yet), you need to add that line to .profile or .bash_profile, that will make to persist such changes, not only to the TTY but for a graphical session as well.
Editing the file /etc/profile and editing the default system PATH, should work as well.
Remember to source any file you have made changes to, ie: source ~/.bashrc, source /etc/profile, source ~/.profile. That way changes take effect immediately or wait until they are executed again; for .bashrc, everytime you open a terminal emulator, for .profile and .bash_profile only once when you log in (unless told otherwise), and for /etc/profile when you start up the system (unless you source it manually, again).
By the way, it is not recommend to have such paths available for normal users. I recommend you to edit /etc/sudoers and give only some permissions to only some users, that will reduce the risk.
There are 3 different types of shells (I think there's only 3 -- anybody feel free to correct me if I'm wrong). Login, interactive, non-interactive. When you first login, a login shell is run (bash -l), and it will source /etc/profile, ~/.profile and ~/.bash_profile. When you have an interactive login (bash without a -l), it will run ~/.bashrc. Non-interactive is if you are running a shell script and has different environment variables than the others.
Certain changes will only affect certain login shells. If you edit /etc/profile (or ~/.bash_profile and a few others), it will only affect login shells and if you edit ~/.bashrc, it will only affect interactive, non-login shells.
I changed my /etc/profile line to add sbin folders to my user's PATH (and only my user's PATH, who has a UID of 1000):
Code:
if [ "`id -u`" = "0" -o "`id -u`" = "1000" ]; then
echo $PATH | grep /usr/local/sbin 1> /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
fi
fi
To ensure I was using /etc/profile for every session, I changed konsole to run bash -l on every new tab.
I don't use interactive non-login shells (there's probably good reasons to use non-login shells, but I'm lazy and my method works for me), but those would only source ~/.bashrc (which you could then have it source /etc/profile).
There are 3 different types of shells (I think there's only 3 -- anybody feel free to correct me if I'm wrong). Login, interactive, non-interactive.
In essence, you are not wrong. It is just that it could be a little bit tricky since you can combine those 3 type of shells and some switches to create a new type of shell, for example, a non-interactive login shell, but those 3 type of shell are still being used just combined, so I would say you are right.
Quote:
Originally Posted by bassmadrigal
Non-interactive is if you are running a shell script and has different environment variables than the others.
Yes, by default that type of shell has that particularity but a non-interactive login shell will still use the environment variables specified in the files sourced by a login shell.
Quote:
Originally Posted by bassmadrigal
Certain changes will only affect certain login shells. If you edit /etc/profile (or ~/.bash_profile and a few others), it will only affect login shells and if you edit ~/.bashrc, it will only affect interactive, non-login shells.
To ensure I was using /etc/profile for every session, I changed konsole to run bash -l on every new tab.
I don't use interactive non-login shells (there's probably good reasons to use non-login shells, but I'm lazy and my method works for me), but those would only source ~/.bashrc (which you could then have it source /etc/profile).
A good reason to use one type of shell or another is that they behave different. For example, you said that you changed Konsole's configuration to use bash as an interactive login shell instead of an interactive non-login shell; let's say that you had a .bash_logout file, such file will be sourced every time you logout or exit from a login shell, and because you use interactive login shells in Konsole, every time you close a tab or window (and that happens pretty often when using terminal emulators), the commands in .bash_logout will be executed. Obviously, that is just one example, there could be more.
Certain changes will only affect certain login shells. If you edit /etc/profile (or ~/.bash_profile and a few others), it will only affect login shells and if you edit ~/.bashrc, it will only affect interactive, non-login shells.
I don't use interactive non-login shells (there's probably good reasons to use non-login shells, but I'm lazy and my method works for me), but those would only source ~/.bashrc (which you could then have it source /etc/profile).
I took a little different approach and edited my ~/.bash_profile script to source ~/.bashrc if its present with something like this:
Code:
# include .bashrc if it exists
if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi
That way the .bashrc file is used for both login and non-login shells. I don't adjust the PATH variable for my user but in this method you could have your "export PATH=..." line in .bashrc and it should always be sourced for either type of interactive shell.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.