You are not logged in.

#1 2016-11-25 10:29:34

ezzetabi
Member
Registered: 2006-08-27
Posts: 947

Change an env variable for all the future executed programs

From the command line it is fairly easy

$ echo $VAR1

$ VAR1=toast bash
$ echo $VAR1
toast
$

But there is a user-wide way?
I tried to play around with systemctl --user import-environment and  systemctl --user set-environment but I could not manage to get any result.

Offline

#2 2016-11-25 10:39:03

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Change an env variable for all the future executed programs

man export

export VAR1=toast

EDIT
After a second read...

But there is a user-wide way?

If you want to set a variable for all applications launched from elsewhere (e.g. in a graphical environment), I don't think there is any way. Setting variables only affects the current shell/application session, not other ones.
The `systemctl set-environment` approach only affects the systemd daemon (although - if you launch applications as systemd services, it might work - but I haven't tried that).

Last edited by ayekat (2016-11-25 10:42:59)


pkgshackscfgblag

Offline

#3 2016-11-25 14:37:47

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Change an env variable for all the future executed programs

Also, when you call bash from within bash like that you're actually starting a new shell:

$ echo $foo

$ echo $$
953
$ foo=bar bash
$ echo $foo
bar
$ echo $$
1391
$ exit
exit
$ echo $foo

$ echo $$
953

($$ is PID)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#4 2016-11-25 22:23:46

seth
Member
Registered: 2012-09-03
Posts: 51,029

Re: Change an env variable for all the future executed programs

This is not how it works - the environment is a process environment. You need to alter it for the shell process that you use to spawn other processes (which will usually inherit the parenting environment)
This is eg. a bash but also krun, gnomedo, plasma-desktop, ....

Altering the process environment from outside is not globally supported (but eg. via dedicated dbus interfaces for few processes, ...)

What exactly are you trying to do (ie. which problem do you seek to solve - altering the env of a running process  is a non globally available solution attempt)

Offline

Board footer

Powered by FluxBB