Where to put the assignment of global environment variables

Volker Wysk post at volker-wysk.de
Thu Sep 15 09:49:33 UTC 2022


Am Donnerstag, dem 15.09.2022 um 00:09 -0700 schrieb Tom Mitchell:
> On Mon, Sep 12, 2022 at 10:49 PM Volker Wysk <post at volker-wysk.de> wrote:
> > 
> > Am Dienstag, dem 13.09.2022 um 07:37 +0200 schrieb Volker Wysk:
> > > Hi!
> > > 
> > > I want to do it right. I have global variables (PATH, MANPATH, INFOPATH),
> > > which need to be extended. I've tried it in /etc/environment, but that
> > > didn't have any effect. On the web, I've found the advice to put it in a
> > > script in /etc/profile.d, but there it gets evaluated *multiple* times.
> > > 
> > > Is that normal? Or where's the intended place for those environment
> > > variables?
> > 
> > Now I'm perplexed. I've rebooted and suddenly it works as expected. Moreso,
> > my "info" terminal in Emacs, which was broken, works again.
> > 
> > With shaking of my head,
> > Volker
> 
> Remember the shell (you did not say which one) will read a sequence of
> files when it starts.

That's clear to me. And it's the vanilla bash shell.

> Rebooting results in you new shell reading the files fresh, putting
> your changes in place.
> 
> You can source  your changes, shells may source with the command "."
> or "source" read more.

Yes, I know that much shell programming.

You can also place your changes in some intended place, which will be
sourced when booting, or when logging in. So they don't need to be sourced
explicitly, in your ~/.bashrc, ~/.profile or ~/.bash_login. /etc/environment
and /etc/environment/* seem NOT to be sourced by a shell, but evaluated
differently, but I'm not sure.

I just wanted to do it the intended way. But it isn't that important after
all.

> Each shell had a fixed set of files to look for and source.
> You could have sourced your changes.  Your new shell picks up
> environment from the old shell
> and from files.   

Yes.

> If you are curios read the man page or run a

Uh-oh. That bash man page is a little excessively long. Better read the
texinfo documentation.

> debugger to see what files are tested for "stat()" and read "open()"
> % vi envtinker
> % cat envtinker
> export UTUuser="VolkerAsked".   # just setting it may not be
> sufficient, so export for the shell I have.
>  %  .  ./envtinker
> % env | grep Volker
> UTUuser=VolkerAsked
> 


Regards,
Volker




More information about the ubuntu-users mailing list