Solved Modifications to bash.bashrc or bashrc

Solved issue

malonn

Member
Joined
May 23, 2023
Messages
53
Reaction score
29
Credits
448
I recently modified bashrc to add a couple items to PATH and XDG_DATA_DIRS. My question is: does this modification take effect system-wide? I mean, using a GUI such as KDE, with its application launchers, will the modified EVs be in effect? Does modifying the titular files give all apps, etc. in the system access to those new EV values, no matter what?

I guess this is a "I'm not 100% sure how Linux works under the hood" question.
 
Last edited:


The .bashrc and .bash_profile in your /home/user directory only affects you.
Every user has their own settings.

On "some" distro's, there is also an /etc/profile file. ( also /etc/profile.d directory )
This is where you can make global ( system wide ) changes.

However, if you're simply adding some path variables, and you want them to be available for
everyone, I would probably use the /etc/environment file. This usually exists, but is sometimes
just a blank file.
 
Okay, cool. I have 1 account on my computer, so that's good. Just so I'm clear, the changes will affect all operations on the computer that use EVs (provided it's my account)? I sort of understood it to mean it takes effect when you launch an interactive shell. I'm just unclear if it means only Konsole (on KDE).
 
Whether the ~/.profile is read from the GUI login depends on the display manager. In the past which I'm familiar with, for gdm, the ~/.profile was read, for sddm, ~/.profile was not read. For the latest, I can't say. The ~/.profile file was readable by a number of shells, whereas the ~/.bash_profile is bash specific.

The bash shell will read ~/.bash_profile, ~/.bash_login, or ~/.profile, but only on a login shell, so if the login is in a GUI bash won't necessarily read these files, rather it will read the ~/.bashrc file once the bash shell is invoked, for example in a terminal. If the default shell is different, e.g. dash or zsh, only the ~/.profile will be read in a login shell.

If the user logs in from text prompt and the shell is bash, the ~/.bash_profile or ~/.profile will be read. Then the GUI can be started with the command: startx, or some other specialised command.

It's easy to check if the ~/.bash_profile file (or any other file) is being read on login, by logging it. To log it, one needs to include inside the ~/.bash_profile (or whatever file is being tested), a line such as:
Code:
echo $(date) ".bash_profile is read" >> /home/<user>/logfile
and start up the logfile with the command:
Code:
touch ~/logfile

Then login in by GUI and check if that log in is being logged in the logfile.

Some GUI logins (if not all) do honour the .xsessionrc file, so if the GUI login is not reading the ~/.profile or a ~/.bash_profile file, it may be worth placing the PATH and environment variables in the ~/.xsessionrc file.
 
Okay, no go... the file was not created. I wonder if it has anything to do with this line in the ~/.bashrc file:
Code:
[[ $- != *i* ]] && return
Comment says if not interactive, don't proceed further (Bash scripting is not my strong suit). I can remove that, or RTM on KDE and fix it. I did come across something saying KDE can run scripts at login.
 
Good to go. ~/.bashrc is read on login by KDE.

Thanks, guys.
 

Members online


Latest posts

Top