[sf-lug] printenv "vs." set [was: Re: shell, man(1) [was: ...
Akkana Peck
akkana at shallowsky.com
Mon Aug 22 09:24:29 PDT 2016
Daniel Gimpelevich writes:
> On Sun, 2016-08-21 at 15:55 -0700, Alex Kleider wrote:
> > It seems that no variable (shell or environment) can exist except in
> > the
> > context of the shell. So does that make them all shell variables?
>
> Variables set from a shell are shell variables. Those that are exported
> are environment variables in processes that inherit them.
To expand on that a little more:
The environment is a set of variables inherited from a process by
its children. So for instance, you might export LESS=-EerX, and then
every process you execute can check your LESS environment variable
if it wants. In practice, the only program that's likely to be
interested in that particular variable is, you guessed it, less.
But there are other environment variables that lots of programs
might be interested in, like HOME (your home directory), DISPLAY
(your X display, so X programs know where to pop up windows), PATH
(where to look for executables), and some optional variables like
LD_LIBRARY_PATH (where to look for libraries) the various LC_*
locale variables (which specify what language and character set
you're using, how you prefer to format dates, and how to sort
alphabetically), EDITOR and VISUAL (what editor do you prefer), etc.
Environment variables don't have to be capitalized; it's just
convention.
A program can change its environment, and any changes it makes will
be passed on to programs it executes. For instance, su - changes
HOME to the new user's home, so any programs you run inside that su -
shell will use the new user's home directory, not your original one.
You can examine the environments of all of your running processes with
ps eww
-- e tells ps to print the environment, w tells it you need lines
wider than the terminal, and the second w tells it you need lines
*really* wider than the terminal. Make it axeww if you want to see
the environments of all processes running on your system: a tells ps
to show processes owned by anyone, not just you, and x says to
include even processes that aren't attached to a terminal.
You'll notice that system processes typically have a much smaller
environment than the ones you're running inside a shell, because you
probably set some environment variables in your login shell.
...Akkana
More information about the sf-lug
mailing list