Reputation: 943
In a graphical DE, like KDE, what command can be used to add a new environment variable that can be used by any other process?
Note:
1) I'm aware of export A=B
, but it only works for subsequent processes started in the same shell that executed the export
, processes started else where, like a graphical application such as Chrome, won't be aware of the export.
2) I'm also aware that you can put it into ~/.bash_profile
or alike, but that would need a restart/relogin for the setting to take effect.
Is there something like export
but have effect for all applications and doesn't require a significant restart?
Upvotes: 0
Views: 519
Reputation: 114320
Your assumption that you need to restart after placing a variable definition (whether through an export
statement or otherwise) in ~/.bash_profile
, is flawed. You only need to source
the file again after making modifications:
source ~/.bash_profile
or the more portable version:
. ~/.bash_profile
Either statement will (re)load any definitions in that file into your current shell. Sourcing is not the same as executing the script: it will modify the environment in the calling shell itself, not a subshell running the script.
A file like ~/.bash_profile
may have many other definitions and settings in it that will mess with the shell. It is better to create a small (temporary) snippet with just the variables you want, and source that instead, as @JeremiahMegel suggests.
If you want to change the environment for a single process you run from the command line, you can set the variables on the same command line:
VAR=value /usr/bin/gedit
This will run gedit
with the environment variable VAR
set to value
, but only for that one child process.
Unfortunately, your desktop applications are a bit more static than that. Most of the graphical applications you see in the menus are probably going to be represented by .desktop
files in a folder like /usr/share/applications
. These files are run in an environment that has almost none of the variables you are expecting. They rely on absolute paths, and most of the configuration is done by pointing the .desktop
file to a script that performs its own setup. You can modify some of these files on an individual basis if you absolutely have to, but I would not recommend doing that. If you do insist on messing around with the graphical apps on your desktop, I would recommend making a copy of the desktop files you plan to modify in to ~/.local/share/applications
, or whatever the equivalent is on your system. Those files will override anything found in /usr/share/applications
and will only affect you.
Upvotes: 1