LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-15-2020, 07:46 PM   #1
levelfourtwenty
LQ Newbie
 
Registered: Jun 2020
Location: Canada
Distribution: Attempting slackware, parrot
Posts: 3

Rep: Reputation: Disabled
Angry changes to $PATH don't persist


(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.
 
Old 06-15-2020, 07:54 PM   #2
levelfourtwenty
LQ Newbie
 
Registered: Jun 2020
Location: Canada
Distribution: Attempting slackware, parrot
Posts: 3

Original Poster
Rep: Reputation: Disabled
fyi, editing ~/.bashrc has been unsuccessful.
 
Old 06-15-2020, 09:26 PM   #3
volkerdi
Slackware Maintainer
 
Registered: Dec 2002
Location: Minnesota
Distribution: Slackware! :-)
Posts: 2,527

Rep: Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501Reputation: 8501
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.
 
1 members found this post helpful.
Old 06-15-2020, 11:19 PM   #4
slac
Member
 
Registered: May 2019
Posts: 265

Rep: Reputation: Disabled
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.
 
Old 06-16-2020, 01:06 AM   #5
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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).
 
1 members found this post helpful.
Old 06-16-2020, 02:41 AM   #6
slac
Member
 
Registered: May 2019
Posts: 265

Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by bassmadrigal View Post
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 View Post
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 View Post
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.
 
Old 06-16-2020, 09:25 AM   #7
0XBF
Member
 
Registered: Nov 2018
Distribution: Slackware
Posts: 771

Rep: Reputation: 875Reputation: 875Reputation: 875Reputation: 875Reputation: 875Reputation: 875Reputation: 875
Quote:
Originally Posted by bassmadrigal View Post
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.
 
Old 06-17-2020, 01:31 PM   #8
levelfourtwenty
LQ Newbie
 
Registered: Jun 2020
Location: Canada
Distribution: Attempting slackware, parrot
Posts: 3

Original Poster
Rep: Reputation: Disabled
Ok thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to persist changes to prompt issacnewton Linux - Newbie 4 08-15-2017 08:26 AM
Changes to persistent Live USB don't persist eco_bach Linux - Newbie 4 12-30-2016 03:48 PM
having linux persist memory changes to disk nickdu Programming 2 07-18-2016 02:49 AM
Volume Levels Set With alsamixer Don't Persist On Reboot mwstroberg Bodhi 6 09-28-2014 08:57 AM
KDE menu editor: changes do not persist xri Slackware 8 10-14-2010 01:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration